AngularJS and Rails Template Engines

As a Rails guy, I adore me Haml or Slim. However, I'm not very lucky when it comes to using AngularJS. Is there a template engine that is AngularJS friendly and less verbose than direct HTML?

+4
source share
2 answers

I use slim for my angularjs templates. It took me a long time to figure out how to do this, but it is very easy to do as soon as you know how to do it.

Add a setting of fine pearls and packages.

Make sure you have a template directory. My:

assets/javascripts/templates 

Then create the file in config / initializers. My just slim_engine.rb. The name does not matter.

Then the following line is included in this file:

 Rails.application.assets.register_engine('.slim', Slim::Template) 

Here is a snippet of the route provider that I have that uses one of these templates:

 angular.module('customer_app', ['customer_service']) .config(['$routeProvider', function($provider) { $provider.when('/:customer_id/edit/', { templateUrl: '/assets/customers/edit.html.slim', controller: 'CustomersController' }); }]) .config(["$httpProvider", function(provider) { provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content'); }]); 

Full path to the template: assets / templates / clients / edit.html.slim

Hope this helps!

+1
source

I wrote about how you can use haml for your angularjs templates with rails and load all the templates correctly in one request here: http://minhajuddin.com/2013/04/28/angularjs-templates-and-rails-with- eager-loading

0
source

All Articles