SlideShare a Scribd company logo
Marrying
AngularJS with Rails
volker.tietz@xing.com
@volkertietz
Marrying angular rails
- <iframe> loads page
- office.js script from MS
- built-in security
- uses postMessage
- provides access to
outlook data
- Cross-platform
Why Angular?
High initialisation
time for Office.js
Full page reloads?
:(
DOM interaction
Where you’re better off
without Angular:
SEO
NoScript
Performance
Best practices
Use promises!
step1(function (value1) {

step2(value1, function(value2) {

step3(value2, function(value3) {

step4(value3, function(value4) {

// All steps successful
});

});

});

});
step1()

.then(function (value1) {

return step2();

})

.then(function (value2) {

return step3();

})

.then(function (value3) {

return step4();

})

.then(function (value4) {

// All steps fulfilled

});
http://tinyurl.com/rughh-promises
Use services as wrappers!
this.save = function () {

var deferred = $q.defer();



roamingSettings().saveAsync(function (asyncResult) {

if (asyncResult.status === $window.Office.AsyncResultStatus.Failed) {

deferred.reject(asyncResult.error.message);

} else {

deferred.resolve();

}

});



return deferred.promise;

};
RoamingSettings.save().then(function () {

// Success!

}, function () {

//Error

});
Directives
angular.module('App')

.directive('foobar', function () {

return {

restrict: 'E',

transclude: true,

require: '?^^parentDirectiveName',

scope: {

name: '@',

data: '=',

callMe: '&'

},

compile: function (elm, attr, transclude) {

return function link(scope, elm, attr, parentDirectiveCtrl) {

}

},

controller: function ($scope, Service) {

}

}

});
https://docs.angularjs.org/guide/directive
Understand the
digest cycle!
Tools
Rails Integration
• Angular as a dependency
• Template handling
• DI Annotations
Dependencies
# Gemfile
gem 'angularjs-rails'
Easiest way
//= require angular/angular
Dependencies
Manage dependencies with bower
# config/initializers/assets.rb
Rails.application.config.assets.paths <<
Rails.root.join('vendor', 'assets', 'components')
// .bowerrc

{

"directory": "vendor/assets/components"

}
$ bower install angularjs
Dependencies
# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w(

office365.js office365.css angular.js
)
Dedicated manifest files
// app/assets/javascripts/office365.js

//= require office365/modules.js

//= require office365/routes.js

//= require office365/config.js

//= require office365/app.js

//= require_tree ./office365/app

//= require_tree ./office365/locales
Dependencies
Dedicated manifest files
// app/assets/javascripts/angular.js

//= require angular/angular

//= require angular-route/angular-route

//= require angular-translate/angular-translate

//= require angular-animate/angular-animate
Templates
Option #1: Rails public folder
• Static templates
• Easy for testing (requires a running server)
• (at least) one request per template
Templates
Option #2: server side rendered
• Dynamic templates
• Harder to test (Rails involved)
Templates
Option #3: angular-rails-templates
• Static templates
• Automatically added to $templateCache

=> no requests
Templates
# Gemfile
gem ‘angular-rails-templates'
Add the gem
# apps/assets/javascripts/office365.js
//= require angular-rails-templates

//= require_tree ./office365/templates
Include it in the asset pipeline
# apps/assets/javascripts/office365/modules.js
angular.module('XNG-Office365-App', ['templates']);
Add it as dependency in your Angular module
Testing Templates
$ npm install karma-ng-html2js-preprocessor
Karma ng-html2js-preprocessor
// karma.conf.js
processors: {

'app/assets/javascripts/office365/templates/*.html': 'ng-html2js'

},
ngHtml2JsPreprocessor: {

// strip this from the file path

stripPrefix: 'app/assets/javascripts/',



// module name

moduleName: 'templates'

}
Add it to the karma config
DI Annotations
angular.module('App')

.controller('ContactsCtrl', function ($scope) {

});
# Gemfile
gem ‘ngannotate-rails'
angular.module('App')

.controller('ContactsCtrl', ['$scope', function ($scope) {

}]);
Conclusions
• AngularJS and Rails play well together
• Rails is often enough!
Questions?

More Related Content

PDF
Active Admin
PPTX
EmberJS BucharestJS
PDF
Active Admin: Create Your Admin Interface the Easy Way
PDF
How angularjs saves rails
PDF
AngularJS meets Rails
PDF
Reacting to the Isomorphic Buzz
ZIP
App engine beats pony.key
PDF
Ruby on Rails - UNISO
Active Admin
EmberJS BucharestJS
Active Admin: Create Your Admin Interface the Easy Way
How angularjs saves rails
AngularJS meets Rails
Reacting to the Isomorphic Buzz
App engine beats pony.key
Ruby on Rails - UNISO

What's hot (19)

PPTX
Going Serverless with Azure Functions
PPTX
Building solutions with the SharePoint Framework - deep-dive
PDF
Rails course day 6
PDF
Web Worker, Service Worker and Worklets
PDF
RoR vs-nodejs-by-jcskyting
PDF
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
ODP
Frontend Finesse with Angular & Rails 4
PPTX
Moving From AngularJS to Angular 2
PDF
Angular Testing
PPTX
Creating asynchronous flows on AWS
PDF
Modern Functional Fluent ColdFusion REST Apis
PPTX
Azure App Services
PPT
Intro to SPA using JavaScript & ASP.NET
PPTX
Web forms Overview Presentation
PDF
Consuming REST services with ActiveResource
ODP
Scheduler_session
PDF
Communication tool & Environment for Remote Worker
PPTX
ASP.NET MVC overview
PDF
Ruby w/o Rails (Олександр Сімонов)
Going Serverless with Azure Functions
Building solutions with the SharePoint Framework - deep-dive
Rails course day 6
Web Worker, Service Worker and Worklets
RoR vs-nodejs-by-jcskyting
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
Frontend Finesse with Angular & Rails 4
Moving From AngularJS to Angular 2
Angular Testing
Creating asynchronous flows on AWS
Modern Functional Fluent ColdFusion REST Apis
Azure App Services
Intro to SPA using JavaScript & ASP.NET
Web forms Overview Presentation
Consuming REST services with ActiveResource
Scheduler_session
Communication tool & Environment for Remote Worker
ASP.NET MVC overview
Ruby w/o Rails (Олександр Сімонов)
Ad

Viewers also liked (7)

PPS
Habilitación de Negocios - Municipalidad de Santa Fe
PPTX
3 concious parenting secrets
DOCX
420FRENutritionResearch
PDF
Comment être un bon patron d'agence digitale?
PPTX
La naturaleza de Dios
PPTX
IMPORTANCIA DE LA BIBLIA EN LA VIDA DEL CREYENTE
PDF
RESEÑA HISTORICA DE LA IGLESIA ASAMBLEAS DE DIOS MINISTERIO LA UNION
Habilitación de Negocios - Municipalidad de Santa Fe
3 concious parenting secrets
420FRENutritionResearch
Comment être un bon patron d'agence digitale?
La naturaleza de Dios
IMPORTANCIA DE LA BIBLIA EN LA VIDA DEL CREYENTE
RESEÑA HISTORICA DE LA IGLESIA ASAMBLEAS DE DIOS MINISTERIO LA UNION
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Digital Logic Computer Design lecture notes
PPTX
OOP with Java - Java Introduction (Basics)
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Geodesy 1.pptx...............................................
PPT
Mechanical Engineering MATERIALS Selection
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
composite construction of structures.pdf
PPTX
Sustainable Sites - Green Building Construction
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
Digital Logic Computer Design lecture notes
OOP with Java - Java Introduction (Basics)
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Geodesy 1.pptx...............................................
Mechanical Engineering MATERIALS Selection
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
composite construction of structures.pdf
Sustainable Sites - Green Building Construction
Automation-in-Manufacturing-Chapter-Introduction.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT 4 Total Quality Management .pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Model Code of Practice - Construction Work - 21102022 .pdf
Operating System & Kernel Study Guide-1 - converted.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS

Marrying angular rails