SlideShare a Scribd company logo
1 of 20
Slides Assembled by: 
Christopher Foo
What is AngularJS? 
A JavaScript framework for creating 
dynamic web applications 
Open Source 
• GitHub: https://github.com/angular/angular.js 
• MIT License 
Uses jQuery 
• jQuery 1.7.1 or above 
• jQLite
MVC 
Model 
• The data 
Controller 
• The behavior 
• Modifying / updating the models 
View 
• The interface 
• How the data is presented to the user 
JavaScript 
HTML
Data Binding 
Views are declarative 
• The structure of the interface 
Controllers do not need to directly 
manipulate the view 
• Changes in the models / data are 
automatically reflected in the view 
• Updates are managed by the frameworks
Sample Application 
GitHub: 
• https://github.com/christophertfoo/AngularSample
Views 
 Make use of special ng attributes (directives) on the 
HTML elements 
• ng-app 
• Determines which part of the page will use AngularJS 
• If given a value it will load that application module 
• ng-controller 
• Determines which Javascript Controller should be used for that 
part of the page 
• ng-model 
• Determines what model the value of an input field will be 
bound to 
• Used for two-way binding
Views 
More ng directives 
• ng-if=“<model expression>” 
• Inserts HTML element if expression is true 
• Does not insert element in the DOM if it is false 
• ng-repeat=“<variable> in <array>” 
• Repeats the HTML element for each value in the 
array 
• Also a key-value pair version for JSON objects 
• “(<key>, <value>) in <JSON>”
Views 
{{ }} 
• Angular expressions 
• Like JavaScript expressions except: 
• Evaluated in the current scope (see Controllers later 
on), not the global window 
• More forgiving to undefined and null errors 
• No control statements: conditionals, loops, or throw 
• Insert model values directly into the view
Controller 
 Function that takes at least one parameter: $scope 
• Function is a constructor 
• Ex: 
• function MyCtrl($scope) { … } 
• We will see a different way of creating a controller 
constructor later 
 $scope 
• JavaScript object 
• Contains data (i.e. models) and methods (i.e. functions) 
• Can add own properties 
• $scope.<my new property> = <value>;
Controller 
 Dependency Injection 
• Pass the modules and services that you need as 
parameters 
• In the previous case $scope is a service that will be 
injected 
• Can be passed as an array of strings to the controller 
function as well 
• Prevents errors when performing minification 
• Other useful services 
• $http 
• Used to handle Ajax calls 
• Wrappers around jQuery
Controller 
Typically also contains module loading 
 angular.module(<name>, [<dependencies>]); 
• Creates a module with the given name 
• This module can then be configured 
• Ex. 
• var myApp = angular.module(‘myApp’, []); 
myApp.controller(‘MyCtrl’, function($scope) { … }); 
myApp.controller(‘OtherCtrl’, [‘$scope’, ‘$http’, 
function($scope, $http) { … }]);
Models 
Properties on the Controller’s $scope 
object 
Standard JavaScript values
Modules 
Can be used to separate the application 
into parts 
Application module can include the other 
modules by listing them as 
dependencies
Modules 
var myControllers = 
angular.module(‘myControllers’, []); 
// Add controllers to the module 
myControllers.controller(…); 
var myApp = angular.module(‘myApp’, 
[‘myControllers’]);
More 
 You can do a lot more with AngularJS 
• Custom directives 
• http://docs.angularjs.org/guide/directive 
• Filters 
• http://docs.angularjs.org/guide/dev_guide.templates.filte 
rs 
 To learn more: 
• Tutorial: http://docs.angularjs.org/tutorial 
• Documentation: 
http://docs.angularjs.org/guide/overview
Thank you for listening! 
Questions / Comments?
Routing 
Use different views for different URL 
fragments 
Makes use of template partials 
• Templates that are not a whole web page (i.e. 
part of a page) 
• Used in conjunction with the ng-view directive 
• ng-view determines where the partial will be placed 
• Can only have one ng-view per page
Routing 
 Enable by injecting the $routeProvider 
• myApp = angular.module(‘myApp’, [‘ngRoute’]); 
myApp.config([‘$routeProvider’, function($routeProvider) { … }]); 
 $routeProvider.when(<path>, {<route>}); 
• Defines a new route that uses the given path 
• The path may have parameters 
• Parameters start with a colon (‘:’) 
• Ex 
• ‘/user/:userId’ 
• Typical route fields: 
• controller = The name of the controller that should be used 
• templateUrl = A path to the template partial that should be used 
 $routeProvider.otherwise({<route>}); 
• Typical route fields: 
• redirectTo: ‘<path>’ 
 API: http://docs.angularjs.org/api/ngRoute.$routeProvider
Routing 
URL parameters 
• To access the parameters in the URL, use the 
$routeParams service 
• The $routeParams object will have a field with 
the same name as the parameter 
• Ex. 
• $routeParams.userId
Routing 
 Paths default to Hashbang mode 
• Example URL. 
• http://www.mysite.com/#/users 
 Can use HTML 5 mode by configuring the 
$locationProvider 
• Ex. 
• // Inject $locationProvider into the module using config 
$locationProvider.html5Mode(true); 
• Example URL: 
• http://www.mysite.com/users

More Related Content

What's hot

Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at DatacomDavid Xi Peng Yang
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS introdizabl
 
Introduction to SPA with AngularJS
Introduction to SPA with AngularJSIntroduction to SPA with AngularJS
Introduction to SPA with AngularJSRiki Pribadi
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)Gary Arora
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSparkhound Inc.
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
SPA, Scalable Application & AngularJS
SPA, Scalable Application & AngularJSSPA, Scalable Application & AngularJS
SPA, Scalable Application & AngularJSMitch Chen
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJSCraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJScraftworkz
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginnersMunir Hoque
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) PresentationRaghubir Singh
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework Yakov Fain
 

What's hot (20)

Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
Spa with angular
Spa with angularSpa with angular
Spa with angular
 
Introduction to SPA with AngularJS
Introduction to SPA with AngularJSIntroduction to SPA with AngularJS
Introduction to SPA with AngularJS
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
SPA, Scalable Application & AngularJS
SPA, Scalable Application & AngularJSSPA, Scalable Application & AngularJS
SPA, Scalable Application & AngularJS
 
CraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJSCraftCamp for Students - Introduction to AngularJS
CraftCamp for Students - Introduction to AngularJS
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
Angular 4
Angular 4Angular 4
Angular 4
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 

Viewers also liked

Asia pacopenstack joe-draft 2012-08-08
Asia pacopenstack joe-draft 2012-08-08Asia pacopenstack joe-draft 2012-08-08
Asia pacopenstack joe-draft 2012-08-08OpenCity Community
 
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...Елена Шальнова
 
Music video theories2
Music video theories2Music video theories2
Music video theories2NShuttle
 
Pathways to improved irrigation performance in Africa
Pathways to improved irrigation performance in AfricaPathways to improved irrigation performance in Africa
Pathways to improved irrigation performance in Africafutureagricultures
 
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)Francis Makamba
 
CSR Metrics: You can't measure temperature with a speedometer!
CSR Metrics: You can't measure temperature with a speedometer!CSR Metrics: You can't measure temperature with a speedometer!
CSR Metrics: You can't measure temperature with a speedometer!Wayne Dunn
 
Dallas 2012 analysis
Dallas 2012 analysisDallas 2012 analysis
Dallas 2012 analysisSammi Wilde
 
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...Kouluterveyskysely
 
Leave your laptop at Home - College Productivity Tip
Leave your laptop at Home - College Productivity TipLeave your laptop at Home - College Productivity Tip
Leave your laptop at Home - College Productivity TipAngad Singh
 
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuellaIlola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuellaKouluterveyskysely
 
Volunteer guidelines 2012
Volunteer guidelines 2012Volunteer guidelines 2012
Volunteer guidelines 2012cokelley
 
Hockey taught me this: NHL Alumni Breakaway Symposium
Hockey taught me this: NHL Alumni Breakaway SymposiumHockey taught me this: NHL Alumni Breakaway Symposium
Hockey taught me this: NHL Alumni Breakaway SymposiumWayne Dunn
 
Kudavi 2.22.2016
Kudavi 2.22.2016Kudavi 2.22.2016
Kudavi 2.22.2016Tom Currier
 

Viewers also liked (20)

Asia pacopenstack joe-draft 2012-08-08
Asia pacopenstack joe-draft 2012-08-08Asia pacopenstack joe-draft 2012-08-08
Asia pacopenstack joe-draft 2012-08-08
 
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
 
Music video theories2
Music video theories2Music video theories2
Music video theories2
 
Pathways to improved irrigation performance in Africa
Pathways to improved irrigation performance in AfricaPathways to improved irrigation performance in Africa
Pathways to improved irrigation performance in Africa
 
Rencana pelaksanaan
Rencana pelaksanaan Rencana pelaksanaan
Rencana pelaksanaan
 
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
 
Oap
OapOap
Oap
 
CSR Metrics: You can't measure temperature with a speedometer!
CSR Metrics: You can't measure temperature with a speedometer!CSR Metrics: You can't measure temperature with a speedometer!
CSR Metrics: You can't measure temperature with a speedometer!
 
Dallas 2012 analysis
Dallas 2012 analysisDallas 2012 analysis
Dallas 2012 analysis
 
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
 
Sports in england
Sports in englandSports in england
Sports in england
 
Back to the future of hr@ams
Back to the future of hr@amsBack to the future of hr@ams
Back to the future of hr@ams
 
KVH Plug & Trade
KVH Plug & TradeKVH Plug & Trade
KVH Plug & Trade
 
Leave your laptop at Home - College Productivity Tip
Leave your laptop at Home - College Productivity TipLeave your laptop at Home - College Productivity Tip
Leave your laptop at Home - College Productivity Tip
 
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuellaIlola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuella
 
I living app
I living appI living app
I living app
 
Volunteer guidelines 2012
Volunteer guidelines 2012Volunteer guidelines 2012
Volunteer guidelines 2012
 
Hockey taught me this: NHL Alumni Breakaway Symposium
Hockey taught me this: NHL Alumni Breakaway SymposiumHockey taught me this: NHL Alumni Breakaway Symposium
Hockey taught me this: NHL Alumni Breakaway Symposium
 
Kudavi 2.22.2016
Kudavi 2.22.2016Kudavi 2.22.2016
Kudavi 2.22.2016
 
Causualconnnie1
Causualconnnie1Causualconnnie1
Causualconnnie1
 

Similar to Angular js

End to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSGil Fink
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupGoutam Dey
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comPerfomatix Solutions
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiLiju Pillai
 
AngularJs Basic Concept
AngularJs Basic ConceptAngularJs Basic Concept
AngularJs Basic ConceptHari Haran
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and conceptsSuresh Patidar
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Ganesh Kondal
 
Angular patterns
Angular patternsAngular patterns
Angular patternsPremkumar M
 

Similar to Angular js (20)

End to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJS
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angularjs
AngularjsAngularjs
Angularjs
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
Angular
AngularAngular
Angular
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju Pillai
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
AngularJs Basic Concept
AngularJs Basic ConceptAngularJs Basic Concept
AngularJs Basic Concept
 
AngularJS
AngularJSAngularJS
AngularJS
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Angular patterns
Angular patternsAngular patterns
Angular patterns
 

Angular js

  • 1. Slides Assembled by: Christopher Foo
  • 2. What is AngularJS? A JavaScript framework for creating dynamic web applications Open Source • GitHub: https://github.com/angular/angular.js • MIT License Uses jQuery • jQuery 1.7.1 or above • jQLite
  • 3. MVC Model • The data Controller • The behavior • Modifying / updating the models View • The interface • How the data is presented to the user JavaScript HTML
  • 4. Data Binding Views are declarative • The structure of the interface Controllers do not need to directly manipulate the view • Changes in the models / data are automatically reflected in the view • Updates are managed by the frameworks
  • 5. Sample Application GitHub: • https://github.com/christophertfoo/AngularSample
  • 6. Views  Make use of special ng attributes (directives) on the HTML elements • ng-app • Determines which part of the page will use AngularJS • If given a value it will load that application module • ng-controller • Determines which Javascript Controller should be used for that part of the page • ng-model • Determines what model the value of an input field will be bound to • Used for two-way binding
  • 7. Views More ng directives • ng-if=“<model expression>” • Inserts HTML element if expression is true • Does not insert element in the DOM if it is false • ng-repeat=“<variable> in <array>” • Repeats the HTML element for each value in the array • Also a key-value pair version for JSON objects • “(<key>, <value>) in <JSON>”
  • 8. Views {{ }} • Angular expressions • Like JavaScript expressions except: • Evaluated in the current scope (see Controllers later on), not the global window • More forgiving to undefined and null errors • No control statements: conditionals, loops, or throw • Insert model values directly into the view
  • 9. Controller  Function that takes at least one parameter: $scope • Function is a constructor • Ex: • function MyCtrl($scope) { … } • We will see a different way of creating a controller constructor later  $scope • JavaScript object • Contains data (i.e. models) and methods (i.e. functions) • Can add own properties • $scope.<my new property> = <value>;
  • 10. Controller  Dependency Injection • Pass the modules and services that you need as parameters • In the previous case $scope is a service that will be injected • Can be passed as an array of strings to the controller function as well • Prevents errors when performing minification • Other useful services • $http • Used to handle Ajax calls • Wrappers around jQuery
  • 11. Controller Typically also contains module loading  angular.module(<name>, [<dependencies>]); • Creates a module with the given name • This module can then be configured • Ex. • var myApp = angular.module(‘myApp’, []); myApp.controller(‘MyCtrl’, function($scope) { … }); myApp.controller(‘OtherCtrl’, [‘$scope’, ‘$http’, function($scope, $http) { … }]);
  • 12. Models Properties on the Controller’s $scope object Standard JavaScript values
  • 13. Modules Can be used to separate the application into parts Application module can include the other modules by listing them as dependencies
  • 14. Modules var myControllers = angular.module(‘myControllers’, []); // Add controllers to the module myControllers.controller(…); var myApp = angular.module(‘myApp’, [‘myControllers’]);
  • 15. More  You can do a lot more with AngularJS • Custom directives • http://docs.angularjs.org/guide/directive • Filters • http://docs.angularjs.org/guide/dev_guide.templates.filte rs  To learn more: • Tutorial: http://docs.angularjs.org/tutorial • Documentation: http://docs.angularjs.org/guide/overview
  • 16. Thank you for listening! Questions / Comments?
  • 17. Routing Use different views for different URL fragments Makes use of template partials • Templates that are not a whole web page (i.e. part of a page) • Used in conjunction with the ng-view directive • ng-view determines where the partial will be placed • Can only have one ng-view per page
  • 18. Routing  Enable by injecting the $routeProvider • myApp = angular.module(‘myApp’, [‘ngRoute’]); myApp.config([‘$routeProvider’, function($routeProvider) { … }]);  $routeProvider.when(<path>, {<route>}); • Defines a new route that uses the given path • The path may have parameters • Parameters start with a colon (‘:’) • Ex • ‘/user/:userId’ • Typical route fields: • controller = The name of the controller that should be used • templateUrl = A path to the template partial that should be used  $routeProvider.otherwise({<route>}); • Typical route fields: • redirectTo: ‘<path>’  API: http://docs.angularjs.org/api/ngRoute.$routeProvider
  • 19. Routing URL parameters • To access the parameters in the URL, use the $routeParams service • The $routeParams object will have a field with the same name as the parameter • Ex. • $routeParams.userId
  • 20. Routing  Paths default to Hashbang mode • Example URL. • http://www.mysite.com/#/users  Can use HTML 5 mode by configuring the $locationProvider • Ex. • // Inject $locationProvider into the module using config $locationProvider.html5Mode(true); • Example URL: • http://www.mysite.com/users