Single Page Applications
with
Angular.js
Danny Vernovsky
dannyv@sela.co.il
@dimkinv
Agenda
• Why web applications are hard?
• Angular.js, how to? (Movie lib)
• Pros & cons
• Q & A
Once upon a time...
In 2005...
In 2013...
MV what?
Model
Controller
View
Angular.js as a framework
• Based on MVC pattern
o application.controller('myCtrl')
• Can extend HTML vocabulary
o application.directive('myElement')
• Injectables
o function($scope, $myService)
• Two way binding
o {{model.firstName}}
Controllers
• Controllers are just functions
• Used to setup initial state with $scope
• Used to setup behaivours
$scope
• Holds the model
• Provide API's (e.g $watch)
• Connects between view and
controller
Demo
Hello Angular
Modules
• No "main" method for application
• Closed package code / reusable
• No load order needed.
application
controllers
services
directives
filters
Directives
• All ng-* are directives!!!
• Extends HTML with behaviour
• Comes in various of flavors
Demo
Movies Lib, Modules + Directives
Services
• Can be declared as service or factory
• Usefull for DOM/data manipulations
• Lazy loaded into memory
Demo
Movies Lib, Services
Filters
• Best used to format expression.
• Can be also used on collections
• Angular.js built-in filters
Demo
Movies Lib, Filters
Single Page Application
• Routes are the core of SPA
• Can respond to deep linking URLs
with $routeProvider
• Rendered templates appied into
ngView directive
Demo
Movies Lib, Complete Example
Lets sum up!
Cons
Takes freedom
Errors not always visible
Complex to master
Pros
Framework brings order
Very easy to start
Very declarative
By Google (here to stay)
Based on known pattern
Created with testability in mind
Whats next?
Angular.js 1.2RC1
• ng-animate with predefined animations
• ‘controller as’ – aliases for controllers
• finally, ng-if
• better error messages for debugging
• better documentation
• And much more
Questions?

Spa with angular