[ rails ] angular

Installation

bower init && bower i angular --save

.bowerrc may need to be changed.

USAGE

app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require angular
//= require app/app_module
//= require controllers/task

app/assets/javascripts/app/app_module.js

var app = angular.module(‘rails-task-list’, [
‘ui.router’
]);

Create Angular application

app/views/layouts/application.html.erb

<!DOCTYPE html>
<html ng-app=’rails-task-list’>
...

app/assets/javascripts/controllers/task.js

app.controller(‘TaskCtrl’, [
‘$scope’,
function($scope){
$scope.message = ‘I come from the angular controller!’;
}]);

app/views/task/index.html.erb

<div class=’container’ ng-controller=’TaskCtrl’>
<div class=’row text-center’>
<h1>Tasks</h1>
<pre>{{message}}</pre>
<ul class=’list-group’>
<% @tasks.each do |task| %>
	<li class=’list-group-item’><%= task.title %></li>
<% end %></ul>
</div>
</div>

ref : https://medium.com/@connorleech/add-angular-js-to-ruby-on-rails-app-8be2104e1238#.tjctn7gfw

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s