Pregunta

I can't for the life of me get templateUrl from a custom directive to link to html template file in my Rails app. I've tried using the angular-rails-templates gem as well as some other methods. Here's what I have so far:

angular application:

window.App = angular.module('myTestApp', ['templates']);

App.directive('testingDiv', [function(){
    console.log('hey')
    return {
        templateUrl: {
            restrict: 'AE',
            templateUrl: 'test.html'
        }
    }
}]);

(I see the console logged message, so I know I'm getting in there)

test_page.html.slim

testing-div

app/assets/templates/test.html

<div>TESTING!!!!</div>

The order I require relevant assets in my application.js file:

//= require angular
//= require angular-rails-templates
//= require angular-ui-bootstrap-tpls
//= require angular-resource
//= require_tree ./angular

UPDATE:

I tried just

return {
  template: '<div>TEST</div>'
}

and it didn't show up either. Think it has something to do with the slim file?

¿Fue útil?

Solución

//= require_tree ../templates or it won't work. I just checked in our code.

Edit: I think there is a mistake in your syntax, fixed version below:

App.directive('testingDiv', [function(){
    console.log('hey')
    return {
       restrict: 'AE',
       templateUrl: 'test.html'
    }
}]);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top