angular-rails-templates: templates are not found

前端 未结 4 925
粉色の甜心
粉色の甜心 2021-01-07 04:08

I have a rails application, using angularjs for the client side development. I try to load a template located in `app/assets/javascripts/templates/\':

myApp         


        
相关标签:
4条回答
  • 2021-01-07 04:32

    I solved this issue by adding "gem 'sprockets'" into the Gemfile

    0 讨论(0)
  • 2021-01-07 04:33

    Practice has shown that you should keep Angular templates in ./public folder. For example make a folder called templates in the public folder. Now you can just call them like this: templateUrl: 'templates/index.html'

    This makes sense as the app/assets/ is indeed only used for javascript and css files. Also you have the html files in app/views, but these are compiled by server because they use .erb extension. What you want is to have regular html files ready to be used any time. So you put them to public folder.

    0 讨论(0)
  • 2021-01-07 04:33

    try this, I hope this will worked.

     myApp.config(function ($routeProvider) {
      $routeProvider.
        when('/', {
         templateUrl: '/index.html',
         controller: 'MainController'
        }).
        otherwise({
         redirectTo: '/'
       });
    });
    
    0 讨论(0)
  • 2021-01-07 04:36

    My problem has been a sprockets incompatibility. Version 2.1.3 works though so I put this in my Gemfile:

    gem 'sprockets', '2.12.3'
    

    And I ran bundle update sprockets and it's all peachy.

    0 讨论(0)
提交回复
热议问题