SlideShare a Scribd company logo
1 of 20
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
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/

More Related Content

What's hot

Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-IIIprinceirfancivil
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJSJohannes Weber
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with MavenKhan625
 
Sails.js Model / ORM introduce
Sails.js Model / ORM introduceSails.js Model / ORM introduce
Sails.js Model / ORM introduce謝 宗穎
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践taobao.com
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSDen Odell
 
Best practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyondBest practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyondFabian Kromer
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0Takuya Tejima
 

What's hot (20)

Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
Backbone
BackboneBackbone
Backbone
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Sails.js Model / ORM introduce
Sails.js Model / ORM introduceSails.js Model / ORM introduce
Sails.js Model / ORM introduce
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Sails js
Sails jsSails js
Sails js
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Meteor iron:router
Meteor iron:routerMeteor iron:router
Meteor iron:router
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
AngularJS
AngularJSAngularJS
AngularJS
 
Express JS
Express JSExpress JS
Express JS
 
Vuex
VuexVuex
Vuex
 
【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践【前端Mvc】之豆瓣说实践
【前端Mvc】之豆瓣说实践
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
Best practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyondBest practice routing in Meteor.js and beyond
Best practice routing in Meteor.js and beyond
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 

Viewers also liked

Claude Jospeh Vernet
Claude Jospeh VernetClaude Jospeh Vernet
Claude Jospeh VernetspsuART
 
Why it’s hard to believe in failure
Why it’s hard to believe in failureWhy it’s hard to believe in failure
Why it’s hard to believe in failureSyed M Zeeshan
 
Reasons Social Media is Bad.
Reasons Social Media is Bad.Reasons Social Media is Bad.
Reasons Social Media is Bad.Syed M Zeeshan
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
Do not submit acc 422 week 3 wiley plus assignment exercises
Do not submit acc 422 week 3 wiley plus assignment    exercisesDo not submit acc 422 week 3 wiley plus assignment    exercises
Do not submit acc 422 week 3 wiley plus assignment exercisesjefferysbush1
 
Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular jsMustafa Gamal
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0Nagaraju Sangam
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorialClaude Tech
 
Angular js introduction by Tania Gonzales
Angular js introduction by Tania GonzalesAngular js introduction by Tania Gonzales
Angular js introduction by Tania GonzalesThoughtworks
 
Angular js quick start
Angular js quick startAngular js quick start
Angular js quick start정기 김
 
Social media etiquette
Social media etiquette Social media etiquette
Social media etiquette Syed M Zeeshan
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - IntroductionSenthil Kumar
 

Viewers also liked (18)

Claude Jospeh Vernet
Claude Jospeh VernetClaude Jospeh Vernet
Claude Jospeh Vernet
 
Why it’s hard to believe in failure
Why it’s hard to believe in failureWhy it’s hard to believe in failure
Why it’s hard to believe in failure
 
Spanning tree protocol
Spanning tree protocolSpanning tree protocol
Spanning tree protocol
 
Dynamics
Dynamics Dynamics
Dynamics
 
Reasons Social Media is Bad.
Reasons Social Media is Bad.Reasons Social Media is Bad.
Reasons Social Media is Bad.
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Do not submit acc 422 week 3 wiley plus assignment exercises
Do not submit acc 422 week 3 wiley plus assignment    exercisesDo not submit acc 422 week 3 wiley plus assignment    exercises
Do not submit acc 422 week 3 wiley plus assignment exercises
 
Introduction to Angular js
Introduction to Angular jsIntroduction to Angular js
Introduction to Angular js
 
Introduction to Angular js 2.0
Introduction to Angular js 2.0Introduction to Angular js 2.0
Introduction to Angular js 2.0
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Angular js introduction by Tania Gonzales
Angular js introduction by Tania GonzalesAngular js introduction by Tania Gonzales
Angular js introduction by Tania Gonzales
 
Angular js quick start
Angular js quick startAngular js quick start
Angular js quick start
 
Ms office History
Ms office HistoryMs office History
Ms office History
 
Social media etiquette
Social media etiquette Social media etiquette
Social media etiquette
 
Basic of MS Outlook
Basic of MS OutlookBasic of MS Outlook
Basic of MS Outlook
 
Valentine with Angular js - Introduction
Valentine with Angular js - IntroductionValentine with Angular js - Introduction
Valentine with Angular js - Introduction
 
Vertical Axis Wind Turbines
Vertical Axis Wind TurbinesVertical Axis Wind Turbines
Vertical Axis Wind Turbines
 

Similar to Hsiu-Yuan Shan's AngularJS Anatomy

Similar to Hsiu-Yuan Shan's AngularJS Anatomy (20)

AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Angular js
Angular jsAngular js
Angular js
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
 
Angular js
Angular jsAngular js
Angular js
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
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 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...
 
Angular js
Angular jsAngular js
Angular js
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]Single page apps_with_cf_and_angular[1]
Single page apps_with_cf_and_angular[1]
 
Aurelia Meetup Paris
Aurelia Meetup ParisAurelia Meetup Paris
Aurelia Meetup Paris
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Hsiu-Yuan Shan's AngularJS Anatomy

  • 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
  • 5.
  • 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/