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?

+2


source to share


4 answers


My problem was inconsistent sprockets

. Version 2.1.3 works, although I put it in mine Gemfile

:

gem 'sprockets', '2.12.3'

      



And I ran bundle update sprockets

and it was all peach.

+8


source


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.

+4


source


try this i hope it works.

 myApp.config(function ($routeProvider) {
  $routeProvider.
    when('/', {
     templateUrl: '/index.html',
     controller: 'MainController'
    }).
    otherwise({
     redirectTo: '/'
   });
});

      

0


source


I solved this problem by adding "gem" sprockets "to Gemfile

0


source







All Articles