SlideShare a Scribd company logo
Hsiu-Yuan Shan
Looking Back
• Code scattering and tangling(Unobtrusive)
• Dependency management(AMD, module)
• Scope(closure)
• The Pyramid of Doom(promise)
• Testing(Jasmine)
Feature
• MVC/MVVM framework
• Module
• Scope
• Templates and Data Bindings
• Directives
• Dependency Injection
• Testable
http://plnkr.co/edit/0xdJwbiGr8EYqav0DFQr
Declare Controller with function
Model
Directive and Bootstrap
Template and Binding
Angular js introduction
Anatomy
• Bootstrap
– By using ng-app
– Support manually by angular.bootstrap(element[,
modules]);
• MVC
– View : DOM and template
– Controller : Javascript Function
– Model : Object Properties
• Data Binding
– Updating view({{interpolation}}) whenever
model($scope[properties]) changes and vice versa
Module
• <html ng-app='moduleName'>
• angular.module('moduleName', [dependencie
s])
• Module API
– config/constant/controller/directive/factory/filter/
provider/run/service/value
Scope
• Each Angular application has exactly one root
scope, but may have several child scopes.
• One created with each controller
• Inherited from $rootScope
• $watch
– observe model mutations
• $apply
– propagate any model changes through the system into
the view from outside of the Angular
http://plnkr.co/edit/D8RaIlT9wWDK55HWZSNp
Directives
• ng-init
• ng-bind
• ng-model
• ng-show/ng-hide
• ng-repeat
• ng-switch
Custom Directives
• Consider creating a custom DSL
• Translating the camel case name into snake case
with these special characters :, -, or _
• Options for directive declaration usage
– element
– attribute
– class
– comment
http://plnkr.co/edit/GQkYJMzYyKHJ8Ufmb1nr
http://plnkr.co/edit/MfTAdjUITyR0IniJf51n
Filters
• Format data for display to the user
• {{ expression
[|filter_name[:parameter_value] ... ] }}
• Build-in filter
currency/date/filter/json/limitTo/lowercase/number
/orderBy/uppercase
• Support custom filter
http://plnkr.co/edit/a23sJj4OQpD1BNcuGfJB
Form
• Directive that instantiates FormController
• Types
– text/checkbox/file/password/email/url/numer/range/date
• Status
– $pristine/$dirty/$valid/$invalid/$error
• Validation
– novalidate/required/pattern/minlength/maxlength/min/m
ax/change
• Class
– ng-invalid/ng-valid/ng-pristine/ng-dirty
http://plnkr.co/edit/dE91ImbqV401OfSMoAFx
Dependency Injection
1. moduleName.controller('Controller',['$scope', 'service1',
'service2'],function(($scope,service1,service2){…….});
2. moduleName.controller('Controller',
function(($scope,service1,service2){…….});
3. function($scope,service1,service2){…….}
• Only first is acceptable if you want to minifying your javascript and
it also recommended by official web site
• Third can be acceptable by adding
$Controller.$inject = ['$scope', 'service1', 'service2']
Promise
Service
• service
– get service from instantiation of your function
module.service( 'serviceName', yourFunction);
• factory
– get factory from the value that is returned by invoking your
function
module.factory( 'factoryName', yourFunction);
• provider
– get provider from instantiation of your function and
invoke $get()
module. provider( ' providerName', yourFunction);
http://plnkr.co/edit/fwxmaFBMofiyGd0du1K4
Service Communication
• $http
– low-level implementation of XHR
– support method
GET/HEAD/POST/DELETE/PUT/JSONP
• $resource
– include the angular-resource.js
– angular.module('myModule', ['ngResource']))
– use inject $resource where needed
Service Communication
• $resource
– Default nethod
– Support Custom Method
http://plnkr.co/edit/XVeWmx512HIuYfRYjYdu
Name Method Is Array
get GET
save POST
query GET true
remove DELETE
delete DELETE
Routing
• Used for deep-linking URLs to controllers and views
• Using $routerProvider to point to the correct view
when coupled with the ngView directive at config
phase
• $routeParams
– Current set of route parameters
– /Chapter/:chapterId/Section/:sectionId ==> {chapterId:1,
sectionId:2}
• $locationProvider
– HashBang Mode
– HTML5 Model
http://plnkr.co/edit/RltdXkVrEXRogJVOYbTO
Best Practices
• Script tag on the bottom of page
• Use ng-cloak or ng-bind instead of {{interpolation}} avoid user see{{}}
• Structuring Business Logic
– Controllers
• should not reference DOM
• should have view behavior
– Services
• should not reference DOM
• singleton
• have logic independent of View
• Scope
– threat as read-only in templates and write-only in controllers
– should be the reference of the model
http://www.youtube.com/watch?v=ZhfUv0spHCY&list=TL126yqdm_Yyk
Resource
• http://angularjs.org/
• http://www.youtube.com/user/angularjs
• https://github.com/jmcunningham/AngularJS-
Learning
• https://github.com/angular/angular.js/wiki/JsFidd
le-Examples
• https://gitcafe.com/Angularjs/Angularjs-
Developer-Guide/tree/master
• http://zouyesheng.com/angular.html
• https://www.facebook.com/groups/augularjs.tw/
Ad

Recommended

An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
Backbone js
Backbone js
Rohan Chandane
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJS
Ran Mizrahi
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
JWORKS powered by Ordina
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
Juliana Lucena
 
Mini-Training: AngularJS
Mini-Training: AngularJS
Betclic Everest Group Tech Team
 
Mule esb
Mule esb
Khan625
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-III
princeirfancivil
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
Visual Engineering
 
AngularJS with RequireJS
AngularJS with RequireJS
Johannes Weber
 
Backbone
Backbone
Glenn De Backer
 
Building and Managing Projects with Maven
Building and Managing Projects with Maven
Khan625
 
Expressjs
Expressjs
Yauheni Nikanovich
 
Spring Web MVC
Spring Web MVC
AathikaJava
 
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
謝 宗穎
 
Angularjs architecture
Angularjs architecture
Michael He
 
Sails js
Sails js
Andrey Kolodnitsky
 
Introduction to VueJS & Vuex
Introduction to VueJS & Vuex
Bernd Alter
 
Meteor iron:router
Meteor iron:router
Pavel Kurnosov
 
AngularJS Basics
AngularJS Basics
Nikita Shounewich
 
AngularJS
AngularJS
Pasi Manninen
 
Express JS
Express JS
Designveloper
 
Vuex
Vuex
Asaquzzaman Mishu
 
【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践
taobao.com
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
Den Odell
 
Best practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyond
Fabian Kromer
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
Takuya Tejima
 
Claude Jospeh Vernet
Claude Jospeh Vernet
spsuART
 
Why it’s hard to believe in failure
Why it’s hard to believe in failure
Syed M Zeeshan
 

More Related Content

What's hot (20)

Building and managing java projects with maven part-III
Building and managing java projects with maven part-III
princeirfancivil
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
Visual Engineering
 
AngularJS with RequireJS
AngularJS with RequireJS
Johannes Weber
 
Backbone
Backbone
Glenn De Backer
 
Building and Managing Projects with Maven
Building and Managing Projects with Maven
Khan625
 
Expressjs
Expressjs
Yauheni Nikanovich
 
Spring Web MVC
Spring Web MVC
AathikaJava
 
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
謝 宗穎
 
Angularjs architecture
Angularjs architecture
Michael He
 
Sails js
Sails js
Andrey Kolodnitsky
 
Introduction to VueJS & Vuex
Introduction to VueJS & Vuex
Bernd Alter
 
Meteor iron:router
Meteor iron:router
Pavel Kurnosov
 
AngularJS Basics
AngularJS Basics
Nikita Shounewich
 
AngularJS
AngularJS
Pasi Manninen
 
Express JS
Express JS
Designveloper
 
Vuex
Vuex
Asaquzzaman Mishu
 
【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践
taobao.com
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
Den Odell
 
Best practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyond
Fabian Kromer
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
Takuya Tejima
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-III
princeirfancivil
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
Visual Engineering
 
AngularJS with RequireJS
AngularJS with RequireJS
Johannes Weber
 
Building and Managing Projects with Maven
Building and Managing Projects with Maven
Khan625
 
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
謝 宗穎
 
Angularjs architecture
Angularjs architecture
Michael He
 
Introduction to VueJS & Vuex
Introduction to VueJS & Vuex
Bernd Alter
 
【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践
taobao.com
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
Den Odell
 
Best practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyond
Fabian Kromer
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
Takuya Tejima
 

Viewers also liked (18)

Claude Jospeh Vernet
Claude Jospeh Vernet
spsuART
 
Why it’s hard to believe in failure
Why it’s hard to believe in failure
Syed M Zeeshan
 
Spanning tree protocol
Spanning tree protocol
'Texture' Mahmud
 
Dynamics
Dynamics
midnightmj29
 
Reasons Social Media is Bad.
Reasons Social Media is Bad.
Syed M Zeeshan
 
Introduction of angular js
Introduction of angular js
Tamer Solieman
 
Do not submit acc 422 week 3 wiley plus assignment exercises
Do not submit acc 422 week 3 wiley plus assignment exercises
jefferysbush1
 
Introduction to Angular js
Introduction to Angular js
Mustafa Gamal
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju Sangam
 
Angular Seminar-js
Angular Seminar-js
Mindfire Solutions
 
Angular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Angular js introduction by Tania Gonzales
Angular js introduction by Tania Gonzales
Thoughtworks
 
Angular js quick start
Angular js quick start
정기 김
 
Ms office History
Ms office History
Syed M Zeeshan
 
Social media etiquette
Social media etiquette
Syed M Zeeshan
 
Basic of MS Outlook
Basic of MS Outlook
Syed M Zeeshan
 
Valentine with Angular js - Introduction
Valentine with Angular js - Introduction
Senthil Kumar
 
Vertical Axis Wind Turbines
Vertical Axis Wind Turbines
verticalaxiswindturbines
 
Claude Jospeh Vernet
Claude Jospeh Vernet
spsuART
 
Why it’s hard to believe in failure
Why it’s hard to believe in failure
Syed M Zeeshan
 
Reasons Social Media is Bad.
Reasons Social Media is Bad.
Syed M Zeeshan
 
Introduction of angular js
Introduction of angular js
Tamer Solieman
 
Do not submit acc 422 week 3 wiley plus assignment exercises
Do not submit acc 422 week 3 wiley plus assignment exercises
jefferysbush1
 
Introduction to Angular js
Introduction to Angular js
Mustafa Gamal
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0
Nagaraju Sangam
 
Angular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Angular js introduction by Tania Gonzales
Angular js introduction by Tania Gonzales
Thoughtworks
 
Angular js quick start
Angular js quick start
정기 김
 
Social media etiquette
Social media etiquette
Syed M Zeeshan
 
Valentine with Angular js - Introduction
Valentine with Angular js - Introduction
Senthil Kumar
 
Ad

Similar to Angular js introduction (20)

AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
 
AngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
Front end development with Angular JS
Front end development with Angular JS
Bipin
 
Angular js
Angular js
Hritesh Saha
 
Basics of AngularJS
Basics of AngularJS
Filip Janevski
 
Angular js-crash-course
Angular js-crash-course
Keith Bloomfield
 
Angular js
Angular js
yogi_solanki
 
The AngularJS way
The AngularJS way
Boyan Mihaylov
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
angularJs Workshop
angularJs Workshop
Ran Wahle
 
AngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Angular Js Basics
Angular Js Basics
أحمد عبد الوهاب
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
Deepu S Nath
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
Azilen Technologies Pvt. Ltd.
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Community
 
Angular js
Angular js
Baldeep Sohal
 
AngularJs-training
AngularJs-training
Pratchaya Suputsopon
 
Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]
ColdFusionConference
 
Aurelia Meetup Paris
Aurelia Meetup Paris
Ahmed Radjdi
 
Ad

Recently uploaded (20)

Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 

Angular js introduction

  • 2. Looking Back • Code scattering and tangling(Unobtrusive) • Dependency management(AMD, module) • Scope(closure) • The Pyramid of Doom(promise) • Testing(Jasmine)
  • 3. Feature • MVC/MVVM framework • Module • Scope • Templates and Data Bindings • Directives • Dependency Injection • Testable
  • 4. http://plnkr.co/edit/0xdJwbiGr8EYqav0DFQr Declare Controller with function Model Directive and Bootstrap Template and Binding
  • 6. Anatomy • Bootstrap – By using ng-app – Support manually by angular.bootstrap(element[, modules]); • MVC – View : DOM and template – Controller : Javascript Function – Model : Object Properties • Data Binding – Updating view({{interpolation}}) whenever model($scope[properties]) changes and vice versa
  • 7. Module • <html ng-app='moduleName'> • angular.module('moduleName', [dependencie s]) • Module API – config/constant/controller/directive/factory/filter/ provider/run/service/value
  • 8. Scope • Each Angular application has exactly one root scope, but may have several child scopes. • One created with each controller • Inherited from $rootScope • $watch – observe model mutations • $apply – propagate any model changes through the system into the view from outside of the Angular http://plnkr.co/edit/D8RaIlT9wWDK55HWZSNp
  • 9. Directives • ng-init • ng-bind • ng-model • ng-show/ng-hide • ng-repeat • ng-switch
  • 10. Custom Directives • Consider creating a custom DSL • Translating the camel case name into snake case with these special characters :, -, or _ • Options for directive declaration usage – element – attribute – class – comment http://plnkr.co/edit/GQkYJMzYyKHJ8Ufmb1nr http://plnkr.co/edit/MfTAdjUITyR0IniJf51n
  • 11. Filters • Format data for display to the user • {{ expression [|filter_name[:parameter_value] ... ] }} • Build-in filter currency/date/filter/json/limitTo/lowercase/number /orderBy/uppercase • Support custom filter http://plnkr.co/edit/a23sJj4OQpD1BNcuGfJB
  • 12. Form • Directive that instantiates FormController • Types – text/checkbox/file/password/email/url/numer/range/date • Status – $pristine/$dirty/$valid/$invalid/$error • Validation – novalidate/required/pattern/minlength/maxlength/min/m ax/change • Class – ng-invalid/ng-valid/ng-pristine/ng-dirty http://plnkr.co/edit/dE91ImbqV401OfSMoAFx
  • 13. Dependency Injection 1. moduleName.controller('Controller',['$scope', 'service1', 'service2'],function(($scope,service1,service2){…….}); 2. moduleName.controller('Controller', function(($scope,service1,service2){…….}); 3. function($scope,service1,service2){…….} • Only first is acceptable if you want to minifying your javascript and it also recommended by official web site • Third can be acceptable by adding $Controller.$inject = ['$scope', 'service1', 'service2']
  • 15. Service • service – get service from instantiation of your function module.service( 'serviceName', yourFunction); • factory – get factory from the value that is returned by invoking your function module.factory( 'factoryName', yourFunction); • provider – get provider from instantiation of your function and invoke $get() module. provider( ' providerName', yourFunction); http://plnkr.co/edit/fwxmaFBMofiyGd0du1K4
  • 16. Service Communication • $http – low-level implementation of XHR – support method GET/HEAD/POST/DELETE/PUT/JSONP • $resource – include the angular-resource.js – angular.module('myModule', ['ngResource'])) – use inject $resource where needed
  • 17. Service Communication • $resource – Default nethod – Support Custom Method http://plnkr.co/edit/XVeWmx512HIuYfRYjYdu Name Method Is Array get GET save POST query GET true remove DELETE delete DELETE
  • 18. Routing • Used for deep-linking URLs to controllers and views • Using $routerProvider to point to the correct view when coupled with the ngView directive at config phase • $routeParams – Current set of route parameters – /Chapter/:chapterId/Section/:sectionId ==> {chapterId:1, sectionId:2} • $locationProvider – HashBang Mode – HTML5 Model http://plnkr.co/edit/RltdXkVrEXRogJVOYbTO
  • 19. Best Practices • Script tag on the bottom of page • Use ng-cloak or ng-bind instead of {{interpolation}} avoid user see{{}} • Structuring Business Logic – Controllers • should not reference DOM • should have view behavior – Services • should not reference DOM • singleton • have logic independent of View • Scope – threat as read-only in templates and write-only in controllers – should be the reference of the model http://www.youtube.com/watch?v=ZhfUv0spHCY&list=TL126yqdm_Yyk
  • 20. Resource • http://angularjs.org/ • http://www.youtube.com/user/angularjs • https://github.com/jmcunningham/AngularJS- Learning • https://github.com/angular/angular.js/wiki/JsFidd le-Examples • https://gitcafe.com/Angularjs/Angularjs- Developer-Guide/tree/master • http://zouyesheng.com/angular.html • https://www.facebook.com/groups/augularjs.tw/