Angular -rails-templates: no templates found
I have a rails app using angularjs for client side development. I am trying to load a template located at `app / assets / javascripts / templates / ':
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: '/index.html',
controller: 'MainController'
}).
otherwise({
redirectTo: '/'
});
}]);
but I always get the error: "Error: [$ compile: tpload] Failed to load template: /index.html".
I tried to move the "templates" folder from javascripts - app / assets / templates and add it to my pipeline load by adding the following line to config / application.rb: config.assets.paths << Rails.root.join("app","assets","templates")
I keep getting the same error message, while I do not use the full path to the template: templateUrl: '/assets/index.html',
.
-
Why is the first method not enough? pearl angular -rails-templates shouldn't look for templates in app / assets / javascripts / templates?
-
Why should I use the full asset path inside my javascript?
source to share
Practice has shown that you should store Angular templates in a folder ./public
. For example, create a folder called templates in the folder public
. Now you can just call them like this:templateUrl: 'templates/index.html'
This makes sense as it is app/assets/
really only used for javascript and css files. Also you have html files in app/views
, but they are compiled by the server because they use the extension .erb
. You want to have regular files html
ready to use whenever you want . Therefore, you put them in a public folder.
source to share