SlideShare a Scribd company logo
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Introduction to SPAs with
AngularJS
@LaurentDuveau
AngularAcademy.ca
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
I have been creating web sites for
20 years…
1995
My JavaScript
won’t work in
Netscape!
2015
Still doing
JavaScript…
… but with
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Agenda
• SPA ?
• AngularJS ?
• Setup and first
project
• Modules
• Controllers
• Directives
• Filters
• Navigation with
Routing
• Services
• REST API
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
SPA ?
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Single Page Application
Not an app with a single page…
Different views loaded into a screen without reloading
everything from scratch
+ routing, history, two-way data binding, dependency
injection, …
SPA are client-centric application… so coded with
JavaScript
… lots of JavaScript… rely on a Framework!
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
AngularJS ?
100% JavaScript Framework
Created in October 2010 by developers inside Google
Final first version in June 2012
Open Source, MIT license
Compatible with IE 9+ and others modern browsers
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Wait… another Js framework ?
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Another Js framework, really !??
“there are more JavaScript frameworks
than JavaScript developers”
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Js frameworks…
Google Trends
http://www.google.com/trends/explore?hl=en#q=backbone.js,+angularjs,+ember.js,+knockout.js
&cmpt=q
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
SETUP AND FIRST SAMPLE!
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Setup
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
First sample
index.htmlbinding
directives
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
The ng-* attributes
Angular Directives
• Custom HTML elements (standard!)
• Ignored by browsers, processed by
Angular
• Manage events and DOM
interactions
• Can have its own controller and
template
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
MODULES
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Modules
• Angular code is written in modules
• Better decoupling, maintenance and
testability
• A module can use other modules
dependenciesmodule
name
AngularJS!
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Modules
index.html
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Modules
index.html
app.js
runs this module
when page load
dependencies
none, for now…
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
CONTROLLERS
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Controller
• Behavior of the application specified in
controllers with functions and variables
controller in
the module
good practice:
write your code in an Immediately
Invoked Function Expression (IIFE)
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Controller
index.html
directive controller name alias
controller
scope
binding
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Controller
index.html
directive controller name alias
controller
scope
binding
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
DEMO!
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
DIRECTIVES
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-model directive
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• Add a button with ng-click
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• Add a button with ng-click
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-disabled directive
app.js
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-disabled directive
app.js
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-hide directive
index.html
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
products array
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-repeat directive
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-repeat directive
index.html
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-class directive
index.html
styles.css
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Directives
• ng-class directive
index.html
styles.css
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
FILTERS
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Filters
index.html
formats for
currency, date, …
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Filters
index.html
formats for
currency, date, …
app.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Bidirectional data binding!
When ng-click changes…
…the expression {{store.displayLimit}} (and limitTo) is
automatically updated!
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
ROUTING
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Routing ?
• Split a page in views and navigate between them.
About Us
View
ng-view
(placeholder)
Index.html
My App
Contact Us
View
#/About
#/Contact
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Routing with ngRoute
• Import angular-route.js
• Inject ngRoute into the module
• Define the routes
var app = angular.module('store', ['store-products', 'ngRoute']);
app.config(["$routeProvider", function ($routeProvider) {
$routeProvider.when("/", {
controller: "StoreController",
controllerAs: "storeCtrl",
templateUrl: "/views/productsList.html"
})
.when("/product/:id", {
controller: "ProductController",
controllerAs: "productCtrl",
templateUrl: "/views/productView.html"
})
.otherwise({ redirectTo: "/" });
}]);
mysite.com/index.html#/product/1
mysite.com/index.html
everything else…
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Routing with ngRoute
• Get Route parameter in the controller
• Use ngView in your page
<body>
<div ng-view=""></div>
. . .
</body>
index.html
app.controller('ProductController', function ($routeParams,
dataService) {
dataService.getProductById($routeParams.id)
.then(function (product) {
. . .
products.js
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
SERVICES
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Services
• Shares functionality and data between
controllers
• Avoids code redundancy
• Implemented as singletons (single
instance)
• AngularJS comes with built-in services
($http, $route, $log, $q, $resource, etc.)
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
$resource and REST API
angular.module('store', ['ngResource'])
.factory('Product', function($resource) {
return $resource('/api/product/:id');
})
.controller('MainCtrl', function(Product) {
var vm = this;
// Get all products
vm.products = Product.query();
// Form data for creating a new product with ng-model
vm.productData = {};
vm.newProduct = function() {
var product = new Product(vm.productData);
product.$save();
}
});
also get(), remove(), delete()
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
© LDEX, 2015 JavaScript Open Day Montreal, November 2015
Angular Training: 3-day course in Canada!

More Related Content

What's hot (20)

PPTX
Angular vs. React
OPITZ CONSULTING Deutschland
 
PDF
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Edureka!
 
PPTX
Talk for DevFest 2021 - GDG Bénin
Ezéchiel Amen AGBLA
 
PDF
Coders Workshop: API First Mobile Development Featuring Angular and Node
Apigee | Google Cloud
 
PDF
Smoothing the Continuous Delivery Path - A Tale of Two Teams
Equal Experts
 
PPTX
Angular CLI : HelloWorld
nikspatel007
 
PDF
GraphQL Bangkok Meetup 6.0
Tobias Meixner
 
PDF
What is Angular version 4?
Troy Miles
 
PDF
Angular 2 : le réveil de la force
Nicolas PENNEC
 
PDF
OSGi for outsiders - Milen Dyankov
mfrancis
 
PDF
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
ESUG
 
PDF
Contributing to Apache Projects and Making Profits
Henry Saputra
 
PDF
Getting started with Angular CLI
Sasha Vinčić
 
PDF
React vs angular (mobile first battle)
Michael Haberman
 
PDF
Getting Started with Angular 2
FITC
 
PDF
ReactJS.NET
Troy Miles
 
PDF
Introduction to angular 2
Dhyego Fernando
 
PDF
Waltz-Controls presentation for Canadian Light Source
Igor Khokhryakov
 
PPTX
Angular 2 and Wijmo 5 - GrapeCity Echo 2016 Tokyo
Alex Ivanenko
 
PDF
Angular coding: from project management to web and mobile deploy
Corley S.r.l.
 
Angular vs. React
OPITZ CONSULTING Deutschland
 
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Edureka!
 
Talk for DevFest 2021 - GDG Bénin
Ezéchiel Amen AGBLA
 
Coders Workshop: API First Mobile Development Featuring Angular and Node
Apigee | Google Cloud
 
Smoothing the Continuous Delivery Path - A Tale of Two Teams
Equal Experts
 
Angular CLI : HelloWorld
nikspatel007
 
GraphQL Bangkok Meetup 6.0
Tobias Meixner
 
What is Angular version 4?
Troy Miles
 
Angular 2 : le réveil de la force
Nicolas PENNEC
 
OSGi for outsiders - Milen Dyankov
mfrancis
 
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
ESUG
 
Contributing to Apache Projects and Making Profits
Henry Saputra
 
Getting started with Angular CLI
Sasha Vinčić
 
React vs angular (mobile first battle)
Michael Haberman
 
Getting Started with Angular 2
FITC
 
ReactJS.NET
Troy Miles
 
Introduction to angular 2
Dhyego Fernando
 
Waltz-Controls presentation for Canadian Light Source
Igor Khokhryakov
 
Angular 2 and Wijmo 5 - GrapeCity Echo 2016 Tokyo
Alex Ivanenko
 
Angular coding: from project management to web and mobile deploy
Corley S.r.l.
 

Viewers also liked (7)

PDF
DevTeach Ottawa - Silverlight5 and HTML5
Frédéric Harper
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PDF
Angular 2... so can I use it now??
Laurent Duveau
 
PPTX
Maximizing ROI in eCommerce with Search
iProspect Canada
 
PDF
Introduction to Angular with TypeScript for .NET Developers
Laurent Duveau
 
PDF
Visual Design with Data
Seth Familian
 
PDF
Build Features, Not Apps
Natasha Murashev
 
DevTeach Ottawa - Silverlight5 and HTML5
Frédéric Harper
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
Angular 2... so can I use it now??
Laurent Duveau
 
Maximizing ROI in eCommerce with Search
iProspect Canada
 
Introduction to Angular with TypeScript for .NET Developers
Laurent Duveau
 
Visual Design with Data
Seth Familian
 
Build Features, Not Apps
Natasha Murashev
 
Ad

Similar to Introduction to SPAs with AngularJS (20)

PDF
Angular js interview question answer for fresher
Ravi Bhadauria
 
PPTX
Angular js 1.3 basic tutorial
Al-Mutaz Bellah Salahat
 
PDF
AngularJS in Production (CTO Forum)
Alex Ross
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PPTX
Module2
Hoàng Lê
 
PPT
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
PPT
Top java script frameworks ppt
Omkarsoft Bangalore
 
PPTX
Introduction to AngularJs
Ahmed Elharouny
 
PDF
Introduction to AngularJS
Aldo Pizzagalli
 
PPTX
Angular workshop - Full Development Guide
Nitin Giri
 
PDF
What are the reasons behind growing popularity of AngularJS.pdf
mohitd6
 
PDF
AngularJS for Web and Mobile
Rocket Software
 
PPTX
Basics of AngularJS
Filip Janevski
 
PPTX
AngularJS - a radically different way of building Single Page Apps
jivkopetiov
 
PPTX
AngularJS is awesome
Eusebiu Schipor
 
PPTX
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
PPT
Angularjs for kolkata drupal meetup
Goutam Dey
 
PDF
Introduction to AngularJS
Jussi Pohjolainen
 
PDF
AngularJS By Vipin
Vipin Mundayad
 
Angular js interview question answer for fresher
Ravi Bhadauria
 
Angular js 1.3 basic tutorial
Al-Mutaz Bellah Salahat
 
AngularJS in Production (CTO Forum)
Alex Ross
 
Getting started with angular js
Maurice De Beijer [MVP]
 
Getting started with angular js
Maurice De Beijer [MVP]
 
Module2
Hoàng Lê
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
Top java script frameworks ppt
Omkarsoft Bangalore
 
Introduction to AngularJs
Ahmed Elharouny
 
Introduction to AngularJS
Aldo Pizzagalli
 
Angular workshop - Full Development Guide
Nitin Giri
 
What are the reasons behind growing popularity of AngularJS.pdf
mohitd6
 
AngularJS for Web and Mobile
Rocket Software
 
Basics of AngularJS
Filip Janevski
 
AngularJS - a radically different way of building Single Page Apps
jivkopetiov
 
AngularJS is awesome
Eusebiu Schipor
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Angularjs for kolkata drupal meetup
Goutam Dey
 
Introduction to AngularJS
Jussi Pohjolainen
 
AngularJS By Vipin
Vipin Mundayad
 
Ad

More from Laurent Duveau (20)

PDF
Shit happens… debugging an Angular app.
Laurent Duveau
 
PDF
8 things you didn't know about the Angular Router, you won't believe #6!
Laurent Duveau
 
PDF
De 0 à Angular en 1h30! (french)
Laurent Duveau
 
PDF
Angular 6, CLI 6, Material 6 (french)
Laurent Duveau
 
PDF
Debugging an Angular App
Laurent Duveau
 
PDF
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PDF
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PDF
Introduction to Angular for .NET Developers
Laurent Duveau
 
PDF
Introduction à Angular 2
Laurent Duveau
 
PPTX
ngconf 2016 (french)
Laurent Duveau
 
PDF
Microsoft Edge pour les développeurs web
Laurent Duveau
 
PDF
Microsoft Edge pour les développeurs web
Laurent Duveau
 
PDF
Xamarin.Forms [french]
Laurent Duveau
 
PDF
Back from Xamarin Evolve 2014
Laurent Duveau
 
PDF
Windows App Studio
Laurent Duveau
 
PDF
Windows 8: Live tiles, badges et notifications toasts [french]
Laurent Duveau
 
PPTX
L'opportunité Windows 8 pour les développeurs
Laurent Duveau
 
PPTX
Building apps for WP8 and Win8
Laurent Duveau
 
Shit happens… debugging an Angular app.
Laurent Duveau
 
8 things you didn't know about the Angular Router, you won't believe #6!
Laurent Duveau
 
De 0 à Angular en 1h30! (french)
Laurent Duveau
 
Angular 6, CLI 6, Material 6 (french)
Laurent Duveau
 
Debugging an Angular App
Laurent Duveau
 
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
Introduction to Angular for .NET Developers
Laurent Duveau
 
Introduction à Angular 2
Laurent Duveau
 
ngconf 2016 (french)
Laurent Duveau
 
Microsoft Edge pour les développeurs web
Laurent Duveau
 
Microsoft Edge pour les développeurs web
Laurent Duveau
 
Xamarin.Forms [french]
Laurent Duveau
 
Back from Xamarin Evolve 2014
Laurent Duveau
 
Windows App Studio
Laurent Duveau
 
Windows 8: Live tiles, badges et notifications toasts [french]
Laurent Duveau
 
L'opportunité Windows 8 pour les développeurs
Laurent Duveau
 
Building apps for WP8 and Win8
Laurent Duveau
 

Recently uploaded (20)

PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 

Introduction to SPAs with AngularJS

  • 1. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Introduction to SPAs with AngularJS @LaurentDuveau AngularAcademy.ca
  • 2. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 I have been creating web sites for 20 years… 1995 My JavaScript won’t work in Netscape! 2015 Still doing JavaScript… … but with
  • 3. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Agenda • SPA ? • AngularJS ? • Setup and first project • Modules • Controllers • Directives • Filters • Navigation with Routing • Services • REST API
  • 4. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 SPA ?
  • 5. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Single Page Application Not an app with a single page… Different views loaded into a screen without reloading everything from scratch + routing, history, two-way data binding, dependency injection, … SPA are client-centric application… so coded with JavaScript … lots of JavaScript… rely on a Framework!
  • 6. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 AngularJS ? 100% JavaScript Framework Created in October 2010 by developers inside Google Final first version in June 2012 Open Source, MIT license Compatible with IE 9+ and others modern browsers
  • 7. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Wait… another Js framework ?
  • 8. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Another Js framework, really !?? “there are more JavaScript frameworks than JavaScript developers”
  • 9. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Js frameworks… Google Trends http://www.google.com/trends/explore?hl=en#q=backbone.js,+angularjs,+ember.js,+knockout.js &cmpt=q
  • 10. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 SETUP AND FIRST SAMPLE!
  • 11. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Setup index.html
  • 12. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 First sample index.htmlbinding directives
  • 13. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 The ng-* attributes Angular Directives • Custom HTML elements (standard!) • Ignored by browsers, processed by Angular • Manage events and DOM interactions • Can have its own controller and template
  • 14. © LDEX, 2015 JavaScript Open Day Montreal, November 2015
  • 15. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 MODULES
  • 16. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Modules • Angular code is written in modules • Better decoupling, maintenance and testability • A module can use other modules dependenciesmodule name AngularJS!
  • 17. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Modules index.html app.js
  • 18. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Modules index.html app.js runs this module when page load dependencies none, for now…
  • 19. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 CONTROLLERS
  • 20. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Controller • Behavior of the application specified in controllers with functions and variables controller in the module good practice: write your code in an Immediately Invoked Function Expression (IIFE) app.js
  • 21. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Controller index.html directive controller name alias controller scope binding app.js
  • 22. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Controller index.html directive controller name alias controller scope binding app.js
  • 23. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 DEMO!
  • 24. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 DIRECTIVES
  • 25. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-model directive
  • 26. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • Add a button with ng-click index.html
  • 27. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • Add a button with ng-click index.html
  • 28. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-disabled directive app.js index.html
  • 29. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-disabled directive app.js index.html
  • 30. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-hide directive index.html app.js
  • 31. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives products array app.js
  • 32. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-repeat directive index.html
  • 33. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-repeat directive index.html
  • 34. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-class directive index.html styles.css
  • 35. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Directives • ng-class directive index.html styles.css
  • 36. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 FILTERS
  • 37. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Filters index.html formats for currency, date, … app.js
  • 38. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Filters index.html formats for currency, date, … app.js
  • 39. © LDEX, 2015 JavaScript Open Day Montreal, November 2015
  • 40. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Bidirectional data binding! When ng-click changes… …the expression {{store.displayLimit}} (and limitTo) is automatically updated!
  • 41. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 ROUTING
  • 42. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Routing ? • Split a page in views and navigate between them. About Us View ng-view (placeholder) Index.html My App Contact Us View #/About #/Contact
  • 43. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Routing with ngRoute • Import angular-route.js • Inject ngRoute into the module • Define the routes var app = angular.module('store', ['store-products', 'ngRoute']); app.config(["$routeProvider", function ($routeProvider) { $routeProvider.when("/", { controller: "StoreController", controllerAs: "storeCtrl", templateUrl: "/views/productsList.html" }) .when("/product/:id", { controller: "ProductController", controllerAs: "productCtrl", templateUrl: "/views/productView.html" }) .otherwise({ redirectTo: "/" }); }]); mysite.com/index.html#/product/1 mysite.com/index.html everything else…
  • 44. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Routing with ngRoute • Get Route parameter in the controller • Use ngView in your page <body> <div ng-view=""></div> . . . </body> index.html app.controller('ProductController', function ($routeParams, dataService) { dataService.getProductById($routeParams.id) .then(function (product) { . . . products.js
  • 45. © LDEX, 2015 JavaScript Open Day Montreal, November 2015
  • 46. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 SERVICES
  • 47. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Services • Shares functionality and data between controllers • Avoids code redundancy • Implemented as singletons (single instance) • AngularJS comes with built-in services ($http, $route, $log, $q, $resource, etc.)
  • 48. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 $resource and REST API angular.module('store', ['ngResource']) .factory('Product', function($resource) { return $resource('/api/product/:id'); }) .controller('MainCtrl', function(Product) { var vm = this; // Get all products vm.products = Product.query(); // Form data for creating a new product with ng-model vm.productData = {}; vm.newProduct = function() { var product = new Product(vm.productData); product.$save(); } }); also get(), remove(), delete()
  • 49. © LDEX, 2015 JavaScript Open Day Montreal, November 2015
  • 50. © LDEX, 2015 JavaScript Open Day Montreal, November 2015
  • 51. © LDEX, 2015 JavaScript Open Day Montreal, November 2015 Angular Training: 3-day course in Canada!