问题
so, I'm trying to use the templates folder in AngularJS instead of the 'views' folders that you'd normally use in Rails.
Things work great when I write everything in html, but what if I want to write things in slim, and still work with AngularJS templates, instead of rails Views?
The answer: angular rails templates
Unfortunately... it doesn't quite work. It adds this at the beginning of my page before it successfully renders the rest from slim into html:
Angular Rails Template // source: app/assets/templates/books/indexx.html.slim
angular.module("templates").run(["$templateCache", function($templateCache) { $templateCache.put("books/indexx.html", '
//the rest of my webpage, beautifully rendered from slim to html****
') }]);
So it's close, but no cigar. I've seen other work arounds for this, involving going into your config folder in rails and adding files and so on... but none of them seemed to work. Any direction I should be looking here? My main goal is just be able to use 'templates' in AngularJS (mainly so I can use the ui router) but be able to write them in SLIM instead of html.
EDIT: Hmm... just restarted my server and now everything works. What's really scary is that everything works without the 'angular rails templates' gem... and also without any special config file in config/initializers/angular_helper.rb
that looks like: # For Slim, remember also to add gem to Gemfile Rails.application.assets.register_engine('.slim', Slim::Template)
All I had to do was call the filename.html.slim
in my ui-router
...and everything works. RESTART THE SERVER I guess is the lesson
Sorry for wasting Stackoverflow space with this
回答1:
When you use Angular Rails Template gem, you have to load your templates over
templateURL: 'foo/bar/index.html'
when you path is app/assets/templates/foo/bar/index.html.
来源:https://stackoverflow.com/questions/24685764/trying-to-use-angular-rails-templates-gem