SlideShare a Scribd company logo
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 (20)

PDF
Introduction to AngularJS
Jussi Pohjolainen
 
PPTX
AngularJS Best Practices
Narek Mamikonyan
 
PDF
Angularjs architecture
Michael He
 
PPTX
Angular js presentation at Datacom
David Xi Peng Yang
 
PPTX
AngularJS intro
dizabl
 
PDF
Spa with angular
Danny Vernovsky
 
PDF
Introduction to SPA with AngularJS
Riki Pribadi
 
PPTX
Introduction to Angular JS
Santhosh Kumar Srinivasan
 
PPTX
Angularjs Basics
Jayantha Sirisena
 
PPTX
Angular js for Beginnners
Santosh Kumar Kar
 
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
PPTX
Single Page Applications in SharePoint with Angular
Sparkhound Inc.
 
PPTX
Angular JS - Introduction
Sagar Acharya
 
PDF
SPA, Scalable Application & AngularJS
Mitch Chen
 
PDF
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
PPTX
Angular js for beginners
Munir Hoque
 
PPTX
Angular 4
Saurabh Juneja
 
PPTX
AngularJs (1.x) Presentation
Raghubir Singh
 
PDF
AngularJS Basics
Nikita Shounewich
 
PDF
Overview of the AngularJS framework
Yakov Fain
 
Introduction to AngularJS
Jussi Pohjolainen
 
AngularJS Best Practices
Narek Mamikonyan
 
Angularjs architecture
Michael He
 
Angular js presentation at Datacom
David Xi Peng Yang
 
AngularJS intro
dizabl
 
Spa with angular
Danny Vernovsky
 
Introduction to SPA with AngularJS
Riki Pribadi
 
Introduction to Angular JS
Santhosh Kumar Srinivasan
 
Angularjs Basics
Jayantha Sirisena
 
Angular js for Beginnners
Santosh Kumar Kar
 
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
Single Page Applications in SharePoint with Angular
Sparkhound Inc.
 
Angular JS - Introduction
Sagar Acharya
 
SPA, Scalable Application & AngularJS
Mitch Chen
 
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Angular js for beginners
Munir Hoque
 
Angular 4
Saurabh Juneja
 
AngularJs (1.x) Presentation
Raghubir Singh
 
AngularJS Basics
Nikita Shounewich
 
Overview of the AngularJS framework
Yakov Fain
 

Viewers also liked (20)

PDF
Asia pacopenstack joe-draft 2012-08-08
OpenCity Community
 
PPT
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Елена Шальнова
 
PPTX
Music video theories2
NShuttle
 
PDF
Pathways to improved irrigation performance in Africa
futureagricultures
 
DOC
Rencana pelaksanaan
Shanty Nurcahya
 
PDF
[Ernest small] top_100_food_plants_the_world's_mo(book_zz.org)
Francis Makamba
 
PDF
CSR Metrics: You can't measure temperature with a speedometer!
Wayne Dunn
 
PPTX
Dallas 2012 analysis
Sammi Wilde
 
PDF
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Kouluterveyskysely
 
DOC
Sports in england
jasmina ivanova
 
PPTX
Back to the future of hr@ams
Antwerp Management School
 
PDF
KVH Plug & Trade
KVH Co. Ltd.
 
PDF
Leave your laptop at Home - College Productivity Tip
Angad Singh
 
PDF
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Kouluterveyskysely
 
PDF
I living app
Bruno Bürgi
 
PPTX
Volunteer guidelines 2012
cokelley
 
PDF
Hockey taught me this: NHL Alumni Breakaway Symposium
Wayne Dunn
 
PDF
Kudavi 2.22.2016
Tom Currier
 
DOCX
Causualconnnie1
Connie's Confidante Consulting
 
Asia pacopenstack joe-draft 2012-08-08
OpenCity Community
 
Лекция И.О. Рясик 28.08. 2014 "Здоровье осенью с продукцией ЮСТ, JUST Щвейцар...
Елена Шальнова
 
Music video theories2
NShuttle
 
Pathways to improved irrigation performance in Africa
futureagricultures
 
Rencana pelaksanaan
Shanty Nurcahya
 
[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!
Wayne Dunn
 
Dallas 2012 analysis
Sammi Wilde
 
Halme: Mitä Kouluterveyskysely kertoo koulun keskeyttämiseen yhteydessä olevi...
Kouluterveyskysely
 
Sports in england
jasmina ivanova
 
Back to the future of hr@ams
Antwerp Management School
 
KVH Plug & Trade
KVH Co. Ltd.
 
Leave your laptop at Home - College Productivity Tip
Angad Singh
 
Ilola: Ryhmätaitoja ja aggression hallintaa koulun tuella
Kouluterveyskysely
 
I living app
Bruno Bürgi
 
Volunteer guidelines 2012
cokelley
 
Hockey taught me this: NHL Alumni Breakaway Symposium
Wayne Dunn
 
Kudavi 2.22.2016
Tom Currier
 
Ad

Similar to Angular js (20)

PPTX
Angular workshop - Full Development Guide
Nitin Giri
 
PDF
AngularJS Workshop
Gianluca Cacace
 
PDF
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PPTX
Intro to AngularJs
SolTech, Inc.
 
PDF
AngularJS Basics
Ravi Mone
 
PDF
AngularJS: Overview & Key Features
Mohamad Al Asmar
 
PDF
Angular.js Primer in Aalto University
SC5.io
 
PPTX
Kalp Corporate Angular Js Tutorials
Kalp Corporate
 
PPTX
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
PPTX
Training On Angular Js
Mahima Radhakrishnan
 
PDF
Introduction to AngularJS By Bharat Makwana
Bharat Makwana
 
PPTX
Understanding angular js
Aayush Shrestha
 
PPTX
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
PPTX
AngularJS.part1
Andrey Kolodnitsky
 
PPT
Introduction to AngularJS
Anass90
 
PPTX
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Learnimtactics
 
PPTX
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Jalal Mostafa
 
Angular workshop - Full Development Guide
Nitin Giri
 
AngularJS Workshop
Gianluca Cacace
 
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
Intro to AngularJs
SolTech, Inc.
 
AngularJS Basics
Ravi Mone
 
AngularJS: Overview & Key Features
Mohamad Al Asmar
 
Angular.js Primer in Aalto University
SC5.io
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate
 
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
Training On Angular Js
Mahima Radhakrishnan
 
Introduction to AngularJS By Bharat Makwana
Bharat Makwana
 
Understanding angular js
Aayush Shrestha
 
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
AngularJS.part1
Andrey Kolodnitsky
 
Introduction to AngularJS
Anass90
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Learnimtactics
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Jalal Mostafa
 
Ad

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