SlideShare a Scribd company logo
An Introduction to
AngularJS
Falk Hartmann

November	
  7th,	
  2013
2/12/13

1

Copyright	
  2013	
  Demandware,	
  Inc.	
  Anc.	
  ther	
  ther	
  rights	
  reserved.	
  
Copyright	
  2013	
  Demandware,	
  I ll	
  o All	
  o rights	
  reserved.
My Main Areas of Expertise
•
•
•
•
•

Java
Markup Languages
Identity and Access Management
OSGi
ActionScript/MXML

Demandware
•
•
•
•

November	
  7th,	
  2013

Develops and operates an enterprise-class cloud commerce platform since 2004
160 retail brands with more than 665 sites world-wide
Offices in Jena, Burlington (MA), Munich, Paris, London
Technologies
- Java, JEE, Spring
- Oracle, MongoDB, Redis, ElasticSearch
- Demandware Script (a JavaScript variant)

2

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Agenda
•
•
•
•
•
•

November	
  7th,	
  2013

What is AngularJS?
Challenges & solutions
Terminology
Sample App I: Hello
Sample App II: Zwitschermaschine
Conclusion

3

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
What is AngularJS?

•
•
•
•

Client-side JavaScript framework (i.e., runs in a browser)
“Superheroic JavaScript MVW Framework”
W = Whatever works for you
Model View Controller vs. Model View View-Model

•

Not a breakthrough, but a smart selection of best of
breed approaches

•
•

Started by Google in 2009
Released as 1.0 in 2012

November	
  7th,	
  2013

4

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Challenges & solutions

November	
  7th,	
  2013

5

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Challenges & solutions
Boilerplate code

Single page applications

Rich user interface
Development speed

Forms

Maintainability

Browser incompatibilities
Testability

November	
  7th,	
  2013

5

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Challenges & solutions
Dependency injection

REST

Boilerplate code

Single page applications
Partials/routing

Templates

Rich user interface
Development speed
MVC
Maintainability

Directives
Forms
(Bidirectional) data binding

Browser incompatibilities

Unit tests
Testability

(Abstraction) services
End to end tests

November	
  7th,	
  2013

5

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Terminology
Module
• Unit for the specification of dependencies (high-level)

Directive
• (UI) Control (defined by yourself or third parties)

View
• HTML page with special tags (“directives”)

Controller
• (Client-side) backend to a view

Scope
• View Model, shared object between view and controller
• Hierarchical

Service
• other application components (defined by AngularJS, yourself or third parties), e.g.,
for communicating with backend services or for using browser functionality in a
browser independent way
November	
  7th,	
  2013

6

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Sample App I: Hello
Minimum Angular Application
• index.html
• app.js

Demo

November	
  7th,	
  2013

7

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Bootstrapping Angular
• Declaring the DOM part to be processed: ng-app=”<module-name>”
• Include Angular: <script src="angular.js"></script>
• Include Angular module: <script src=”app.js”></script>

Client-side templates
• Parts of DOM are bound to values in the scope
• Standard Syntax: {{expression}}

Bidirectional data-binding
•
•
•
•

November	
  7th,	
  2013

Button: ng-click
Input: ng-model
Title: ng-bind-template
Image: ng-href

8

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Naming of attributes/elements defined by/with AngularJS
•
•
•
•

November	
  7th,	
  2013

ng-model
ng:model (XML)
data-ng-model (HTML 5)
x-ng-model (XHTML)

9

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Sample App II: Zwitschermaschine

November	
  7th,	
  2013

10

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Step 1: Partials/Routing
Demo

November	
  7th,	
  2013

11

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Dependency Injection
• Controller is registered at module along with its dependencies
• Syntax:
controller('Controller',
['dep1', 'dep2', ...,
function(dep1, dep2, ...) { ... }
])
• Array of size n+1 containing
- n Strings defining dependencies (by name)
- a function with n parameters

Partials/routing
•
•
•
•

November	
  7th,	
  2013

Single page application: constant frame with variable content
Variable content selected via URL
Insertion point for partial pages: ng-view
Configuration of content: $routeProvider

12

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Step 2: Adding a Form
Demo

November	
  7th,	
  2013

13

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Controller
• Defines scope for associated form
• Syntax: ng-controller

Bidirectional data binding

• Retrieval a value first from controller’s scope, than from $rootScope
• Setting a value to the controller’s scope

November	
  7th,	
  2013

14

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Step 3: REST communication
Demo

November	
  7th,	
  2013

15

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
ngResource
• Separate AngularJS module
• Powerful abstraction of REST communication

Client-side templates
• Loops: ng-repeat
• Filters: {{ expression | filter }}
• Forcing an update of the view: $scope.$apply

November	
  7th,	
  2013

16

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Step 4: Directives
Demo

November	
  7th,	
  2013

17

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Directives
• Registration at module
• Usage as element, attribute, class or comment: restrict: ’EAMC’
- Element (E) <custom-ctrl title=”Title”/>
- Attribute (A) <div custom-ctrl=”Title”/>
<div class=”custom-ctrl:Title”/>
- Class (C)
- Comment (M) <!-- directive: custom-ctrl Title -->
• Isolated scope: scope {attributeName: ’@|=|&’}
- Fosters reusability
- Value (@) Pass attribute value as string literal
- Bound (=) Establish data binding between directive and parent scope
- Function (&) Pass a function in the parent scope

November	
  7th,	
  2013

18

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Directives
• Defining the content
- Template: template: { ... } / templateUrl: { ... }
Can replace the directive: replace: true
Can add to the directive’s parent element: replace: false
Can include the directive’s content:
transclude: true + ng:transclude
- Pair of compile/link functions
compile function is invoked once on the directive
link function is invoked once per use of the directive
• Communication between directives
• Priority definition to influence evaluation order
• Existing directives: charting, grids etc.

November	
  7th,	
  2013

19

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Step 5: Testing
Demo

November	
  7th,	
  2013

20

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Summary
Unit tests
• Jasmine syntax to specify tests: describe/it
• Karma for test execution
- Browser configurable (Chrome, Firefox, Safari, IE, PhantomJS)
- auto-watch possible

End-to-end tests

• Capabilities to mock HTTP servers
• UI introspection using jquery selectors
• Karma for test execution

November	
  7th,	
  2013

21

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Conclusion
Logic at the right place
• JSP “This shouldn’t be done here!”
• Angular “This is the right place!”

Well-thought aggregation of established techniques
• Dependency injection as new mean in the JavaScript technological space
• Adaption of known best-of-breed approaches

Under development
• Sometimes libraries change (too) fast

November	
  7th,	
  2013

22

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Thank you!

November	
  7th,	
  2013

23

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Predefined Services
$rootScope

Access to the parent of all scopes (“root scope”)

$location

Access to URL in address bar

$routeProvider

Definition of URL/partials mapping

$compile

Compiles HTML with angular directives

$http

Service for low-level HTTP communication

$resource

High-level REST communication

$log

Abstraction of console.log

...

November	
  7th,	
  2013

24

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Module API
config(configFn)

Configuration function to be executed during module loading

constant(name, object)

Registration of an application-wide constant

controller(name, ctor)

Registration of a controller

directive(name, ctor)

Registration of a directive

filter(name, ctor)

Registration of a filter

run(initFn)

Run function to be executed directly before the application
gets accessible by the user

service(name, ctor)

Registration of a constructor method that new is invoked on to
retrieve an object

factory(name, factory)

Registration of a function that is responsible for creating an
object

provider(name, factory)

Combination of factory and service, only providers are
accessible in config invocations

November	
  7th,	
  2013

25

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.
Configuring couchdb
CouchDB & Futon
• Used version: 1.3.1

default.ini

• Enable CORS
[httpd]
enable_cors = true
[cors]
origins = *

November	
  7th,	
  2013

26

Copyright	
  2013	
  Demandware,	
  Inc.	
  All	
  other	
  rights	
  reserved.

More Related Content

What's hot (20)

PDF
slingmodels
Ankur Chauhan
 
PDF
Backbone JS for mobile apps
Ivano Malavolta
 
PDF
Modern development paradigms
Ivano Malavolta
 
PDF
AEM Sightly Template Language
Gabriel Walt
 
PDF
AngularJS Basics
Nikita Shounewich
 
PDF
Sling Models Using Sightly and JSP by Deepak Khetawat
AEM HUB
 
PDF
Web Components v1
Mike Wilcox
 
PDF
[2015/2016] Backbone JS
Ivano Malavolta
 
PDF
Apache Sling Generic Validation Framework
Radu Cotescu
 
PDF
EVOLVE'14 | Enhance | Gabriel Walt | Sightly Component Development
Evolve The Adobe Digital Marketing Community
 
PDF
AngularJS Basics and Best Practices - CC FE &UX
JWORKS powered by Ordina
 
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
PDF
Handlebars & Require JS
Ivano Malavolta
 
PPTX
HTL(Sightly) - All you need to know
Prabhdeep Singh
 
PDF
Wt unit 5 client &amp; server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PDF
The Modern Java Web Developer - JavaOne 2013
Matt Raible
 
PDF
AEM Sightly Deep Dive
Gabriel Walt
 
PDF
Introduction to React Native
Rami Sayar
 
PDF
Angular or Backbone: Go Mobile!
Doris Chen
 
PPTX
Angular js
Manav Prasad
 
slingmodels
Ankur Chauhan
 
Backbone JS for mobile apps
Ivano Malavolta
 
Modern development paradigms
Ivano Malavolta
 
AEM Sightly Template Language
Gabriel Walt
 
AngularJS Basics
Nikita Shounewich
 
Sling Models Using Sightly and JSP by Deepak Khetawat
AEM HUB
 
Web Components v1
Mike Wilcox
 
[2015/2016] Backbone JS
Ivano Malavolta
 
Apache Sling Generic Validation Framework
Radu Cotescu
 
EVOLVE'14 | Enhance | Gabriel Walt | Sightly Component Development
Evolve The Adobe Digital Marketing Community
 
AngularJS Basics and Best Practices - CC FE &UX
JWORKS powered by Ordina
 
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
Handlebars & Require JS
Ivano Malavolta
 
HTL(Sightly) - All you need to know
Prabhdeep Singh
 
Wt unit 5 client &amp; server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
The Modern Java Web Developer - JavaOne 2013
Matt Raible
 
AEM Sightly Deep Dive
Gabriel Walt
 
Introduction to React Native
Rami Sayar
 
Angular or Backbone: Go Mobile!
Doris Chen
 
Angular js
Manav Prasad
 

Similar to An Introduction to AngularJS (20)

PPTX
Practical AngularJS
Wei Ru
 
PPTX
The AngularJS way
Boyan Mihaylov
 
PPTX
Basics of AngularJS
Filip Janevski
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PPTX
Front end development with Angular JS
Bipin
 
PDF
AngularJS Workshop
Gianluca Cacace
 
PPTX
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
PPTX
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
PDF
AngularJS for Web and Mobile
Rocket Software
 
PDF
What are the reasons behind growing popularity of AngularJS.pdf
mohitd6
 
PPTX
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
PDF
Getting Started With AngularJS
Edureka!
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PDF
Angular js gtg-27feb2013
Nitya Narasimhan
 
PPTX
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
PDF
Beginning AngularJS
Troy Miles
 
PDF
AngularJS Beginner Day One
Troy Miles
 
PDF
Getting Started with AngularJS
Edureka!
 
Practical AngularJS
Wei Ru
 
The AngularJS way
Boyan Mihaylov
 
Basics of AngularJS
Filip Janevski
 
Getting started with angular js
Maurice De Beijer [MVP]
 
Getting started with angular js
Maurice De Beijer [MVP]
 
Front end development with Angular JS
Bipin
 
AngularJS Workshop
Gianluca Cacace
 
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
AngularJS for Web and Mobile
Rocket Software
 
What are the reasons behind growing popularity of AngularJS.pdf
mohitd6
 
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
Getting Started With AngularJS
Edureka!
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Angular js gtg-27feb2013
Nitya Narasimhan
 
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
Beginning AngularJS
Troy Miles
 
AngularJS Beginner Day One
Troy Miles
 
Getting Started with AngularJS
Edureka!
 
Ad

More from Falk Hartmann (9)

PDF
Risikomanagement in der Softwareentwicklung
Falk Hartmann
 
PDF
Risiko Management in der Softwareentwicklung
Falk Hartmann
 
PPT
D3ML Session
Falk Hartmann
 
PPT
An Architecture for an XML-Template Engine enabling Safe Authoring
Falk Hartmann
 
PPT
A Distributed Staged Architecture for Multimodal Applications
Falk Hartmann
 
PDF
Drahtwanderung: Wir machen den NeXTen Schritt
Falk Hartmann
 
PPTX
Technologieraum übergreifende Programmierung
Falk Hartmann
 
PPTX
Sichere templategestützte Verarbeitung von XML-Dokumenten
Falk Hartmann
 
PPTX
Protocol Engineering: Beschreibung und Entwicklung von Kommunikationsprotokollen
Falk Hartmann
 
Risikomanagement in der Softwareentwicklung
Falk Hartmann
 
Risiko Management in der Softwareentwicklung
Falk Hartmann
 
D3ML Session
Falk Hartmann
 
An Architecture for an XML-Template Engine enabling Safe Authoring
Falk Hartmann
 
A Distributed Staged Architecture for Multimodal Applications
Falk Hartmann
 
Drahtwanderung: Wir machen den NeXTen Schritt
Falk Hartmann
 
Technologieraum übergreifende Programmierung
Falk Hartmann
 
Sichere templategestützte Verarbeitung von XML-Dokumenten
Falk Hartmann
 
Protocol Engineering: Beschreibung und Entwicklung von Kommunikationsprotokollen
Falk Hartmann
 
Ad

Recently uploaded (20)

PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
July Patch Tuesday
Ivanti
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 

An Introduction to AngularJS

  • 1. An Introduction to AngularJS Falk Hartmann November  7th,  2013 2/12/13 1 Copyright  2013  Demandware,  Inc.  Anc.  ther  ther  rights  reserved.   Copyright  2013  Demandware,  I ll  o All  o rights  reserved.
  • 2. My Main Areas of Expertise • • • • • Java Markup Languages Identity and Access Management OSGi ActionScript/MXML Demandware • • • • November  7th,  2013 Develops and operates an enterprise-class cloud commerce platform since 2004 160 retail brands with more than 665 sites world-wide Offices in Jena, Burlington (MA), Munich, Paris, London Technologies - Java, JEE, Spring - Oracle, MongoDB, Redis, ElasticSearch - Demandware Script (a JavaScript variant) 2 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 3. Agenda • • • • • • November  7th,  2013 What is AngularJS? Challenges & solutions Terminology Sample App I: Hello Sample App II: Zwitschermaschine Conclusion 3 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 4. What is AngularJS? • • • • Client-side JavaScript framework (i.e., runs in a browser) “Superheroic JavaScript MVW Framework” W = Whatever works for you Model View Controller vs. Model View View-Model • Not a breakthrough, but a smart selection of best of breed approaches • • Started by Google in 2009 Released as 1.0 in 2012 November  7th,  2013 4 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 5. Challenges & solutions November  7th,  2013 5 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 6. Challenges & solutions Boilerplate code Single page applications Rich user interface Development speed Forms Maintainability Browser incompatibilities Testability November  7th,  2013 5 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 7. Challenges & solutions Dependency injection REST Boilerplate code Single page applications Partials/routing Templates Rich user interface Development speed MVC Maintainability Directives Forms (Bidirectional) data binding Browser incompatibilities Unit tests Testability (Abstraction) services End to end tests November  7th,  2013 5 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 8. Terminology Module • Unit for the specification of dependencies (high-level) Directive • (UI) Control (defined by yourself or third parties) View • HTML page with special tags (“directives”) Controller • (Client-side) backend to a view Scope • View Model, shared object between view and controller • Hierarchical Service • other application components (defined by AngularJS, yourself or third parties), e.g., for communicating with backend services or for using browser functionality in a browser independent way November  7th,  2013 6 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 9. Sample App I: Hello Minimum Angular Application • index.html • app.js Demo November  7th,  2013 7 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 10. Summary Bootstrapping Angular • Declaring the DOM part to be processed: ng-app=”<module-name>” • Include Angular: <script src="angular.js"></script> • Include Angular module: <script src=”app.js”></script> Client-side templates • Parts of DOM are bound to values in the scope • Standard Syntax: {{expression}} Bidirectional data-binding • • • • November  7th,  2013 Button: ng-click Input: ng-model Title: ng-bind-template Image: ng-href 8 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 11. Summary Naming of attributes/elements defined by/with AngularJS • • • • November  7th,  2013 ng-model ng:model (XML) data-ng-model (HTML 5) x-ng-model (XHTML) 9 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 12. Sample App II: Zwitschermaschine November  7th,  2013 10 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 13. Step 1: Partials/Routing Demo November  7th,  2013 11 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 14. Summary Dependency Injection • Controller is registered at module along with its dependencies • Syntax: controller('Controller', ['dep1', 'dep2', ..., function(dep1, dep2, ...) { ... } ]) • Array of size n+1 containing - n Strings defining dependencies (by name) - a function with n parameters Partials/routing • • • • November  7th,  2013 Single page application: constant frame with variable content Variable content selected via URL Insertion point for partial pages: ng-view Configuration of content: $routeProvider 12 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 15. Step 2: Adding a Form Demo November  7th,  2013 13 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 16. Summary Controller • Defines scope for associated form • Syntax: ng-controller Bidirectional data binding • Retrieval a value first from controller’s scope, than from $rootScope • Setting a value to the controller’s scope November  7th,  2013 14 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 17. Step 3: REST communication Demo November  7th,  2013 15 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 18. Summary ngResource • Separate AngularJS module • Powerful abstraction of REST communication Client-side templates • Loops: ng-repeat • Filters: {{ expression | filter }} • Forcing an update of the view: $scope.$apply November  7th,  2013 16 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 19. Step 4: Directives Demo November  7th,  2013 17 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 20. Summary Directives • Registration at module • Usage as element, attribute, class or comment: restrict: ’EAMC’ - Element (E) <custom-ctrl title=”Title”/> - Attribute (A) <div custom-ctrl=”Title”/> <div class=”custom-ctrl:Title”/> - Class (C) - Comment (M) <!-- directive: custom-ctrl Title --> • Isolated scope: scope {attributeName: ’@|=|&’} - Fosters reusability - Value (@) Pass attribute value as string literal - Bound (=) Establish data binding between directive and parent scope - Function (&) Pass a function in the parent scope November  7th,  2013 18 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 21. Summary Directives • Defining the content - Template: template: { ... } / templateUrl: { ... } Can replace the directive: replace: true Can add to the directive’s parent element: replace: false Can include the directive’s content: transclude: true + ng:transclude - Pair of compile/link functions compile function is invoked once on the directive link function is invoked once per use of the directive • Communication between directives • Priority definition to influence evaluation order • Existing directives: charting, grids etc. November  7th,  2013 19 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 22. Step 5: Testing Demo November  7th,  2013 20 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 23. Summary Unit tests • Jasmine syntax to specify tests: describe/it • Karma for test execution - Browser configurable (Chrome, Firefox, Safari, IE, PhantomJS) - auto-watch possible End-to-end tests • Capabilities to mock HTTP servers • UI introspection using jquery selectors • Karma for test execution November  7th,  2013 21 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 24. Conclusion Logic at the right place • JSP “This shouldn’t be done here!” • Angular “This is the right place!” Well-thought aggregation of established techniques • Dependency injection as new mean in the JavaScript technological space • Adaption of known best-of-breed approaches Under development • Sometimes libraries change (too) fast November  7th,  2013 22 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 25. Thank you! November  7th,  2013 23 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 26. Predefined Services $rootScope Access to the parent of all scopes (“root scope”) $location Access to URL in address bar $routeProvider Definition of URL/partials mapping $compile Compiles HTML with angular directives $http Service for low-level HTTP communication $resource High-level REST communication $log Abstraction of console.log ... November  7th,  2013 24 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 27. Module API config(configFn) Configuration function to be executed during module loading constant(name, object) Registration of an application-wide constant controller(name, ctor) Registration of a controller directive(name, ctor) Registration of a directive filter(name, ctor) Registration of a filter run(initFn) Run function to be executed directly before the application gets accessible by the user service(name, ctor) Registration of a constructor method that new is invoked on to retrieve an object factory(name, factory) Registration of a function that is responsible for creating an object provider(name, factory) Combination of factory and service, only providers are accessible in config invocations November  7th,  2013 25 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.
  • 28. Configuring couchdb CouchDB & Futon • Used version: 1.3.1 default.ini • Enable CORS [httpd] enable_cors = true [cors] origins = * November  7th,  2013 26 Copyright  2013  Demandware,  Inc.  All  other  rights  reserved.