SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Angular.JS
Advanced Angular.JS - GDayX VN 2013
About me
Nicolas Embleton, French in Ho Chi Minh City
•
•
•
•

2005 - Software Engineer and System Architect, working on legacy tech
stacks (C++, OpenGL, Java, ...) then quickly Web (PHP)
2009 - Founded a Mobile Development Company of 30 individuals
2011 - Started Datafield Startup, Co-founder, CTO
2013 - Started the Javascript Ho Chi Minh City meetup, Getting active in
Startup Vietnamese scene to support and mentor young talents
Agenda

•
•
•
•
•
•
•
•

Quick Intro
Bootstrapping
Why Angular?
Main features, and why it's awesome
Best practices
Testing, tooling
And SEO?
Final words
Intro (quick)
From Wikipedia:

AngularJS is built around the belief that declarative programming

should be used for

building UIs and

wiring software components, while imperative programming is excellent for expressing business
logic. The framework adapts and extends traditional HTML to better serve dynamic content through two-way
data-binding that allows for the automatic synchronization of models and views. As a result, AngularJS deemphasizes
DOM manipulation and improves testability.
Angular JS quick review

•
•
•
•
•
•
•

Templating
Model View Controller (MVC)
Extends HTML (very flexible)
2-ways Data-binding
Very reusable (if you follow best practices)
Improves testability (because it is reusable)
Provides routing, history, jqLite, ...
Bootstrapping

•

Using angular-seeds

•

Using yeoman (excellent workflow tool)

o git clone https://github.com/angular/angular-seed.git
o node scripts/web-server.js
o open http://localhost:8000/app/index.html

o
o
o
o
o

(sudo) npm install -g yo
(sudo) npm install -g generator-angular
yo angular
bower install angular-ui
grunt server
Now, the meat, the main features

•
•
•
•
•
•

Templating
Routing
2-ways data-binding
Directives, services
Dependency Injection
Inter-components Communication
Templating

•

Models

•

Built-in directives

2-way binding
o Easy property mapping
o

ngView
 Where the routing happens
o ngRepeat
 Iterator
o ngIf
o ngSwitch
o
Templating - Conditional with ngIf
<div ng-repeat="message in data.messages" ng-class="message.type">
<hr>
<div ng-if="showFrom(message)">
<div>From: {{message.from.name}}</div>
</div>
<div ng-if="showCreatedBy(message)">
<div>Created by: {{message.createdBy.name}}</div>
</div>
<div ng-if="showTo(message)">
<div>To: {{message.to.name}}</div>
</div>
</div>​
Templating - Nested repeat
<div ng-repeat="group in groups"><!-- 1st ng-repeat level -->
<h2>{{ group.label }}</h2>
<ul>
<li ng-repeat="friend in group.friends">
<!-- 2nd ng-repeat level -->
{{ friend.name }}
</li>
</ul><!-- END: Inner ngRepeat. -->
</div><!-- END: Outer ngRepeat. -->​
Templating - Example 2 - Switch
<div ng-switch on="selection" >
<div ng-switch-when="settings">Settings Div</div>
<span ng-switch-when="home">Home Span</span>
<span ng-switch-default>default</span>
</div>​
Example 2.2 - Switch with 2-way
bind
<div ng-controller="Ctrl">
<select ng-model="selection" ng-options="item for item in items">
</select>
<tt>selection={{selection}}</tt>
<hr/>
<div class="animate-switch-container"
ng-switch on="selection">
<div ng-switch-when="settings">Settings Div</div>
<div ng-switch-when="home">Home Span</div>
<div ng-switch-default>default</div>
</div>
</div>
Templating - Simple ngRepeat
<li ng-repeat="item in items">
Item: {{ item }}
</li>
Templating - Complex ngRepeat
<header ng-repeat-start="item in items">
Header {{ item }}
</header>
<div class="body">
Body {{ item }}
</div>
<footer ng-repeat-end>
Footer {{ item }}
</footer>
Compiling
// compile the new DOM and link it to the current scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
Templating - Routing

•
•
•
•

Happens in ngView
Routing is a very powerful feature
Allows to update "pieces" of the page
Can stream files from disk to make it truly
isolated
2-ways data-binding
•
•
•
•

Becoming more standard, thanks to frameworks like Ember.js or Angular.js

•

Example

Linking 2 fields for synchronization purpose
Linking data to model
Automatically updating the template as data is changed
o Arrays / Collections
o Inputs
o etc…
2-ways data-binding, example
<input type="text" ng-model="title" style="width: 90%"/>
<div ng-app="myapp">
<div ng-controller="mycontroller">
Title: {{ title }} <!-- 2-way data binding -->
<hr>
<div class="zippy" zippy-title="title"></div>
</div>
</div>​
Directives

•
•
•

Angular.js killer feature
Great deal of re-usability
Just look for directives at ngmodules.org
Restricting Directives

•
•
•
•
•

"E": Element, <my-directive>
"A": Attribute, <div my-directive>
"C": Class, <div class="my-directive">
"M": Comment: <!-- directive: my-directive exp -->
Combine (e.g. "EA") for more flexibility
Communicating between directives

•
•

Many design patterns
The "backbonier"

•

A more connected example

o

o

the emitter and the receiver
the directive combinations and controller sharing
Communicating between directives
app.directive('directiveA', function($rootScope){
return function(scope, element, attrs) {

// $rootScope = App Scope
// scope = Current scope (ctrl)

$rootScope.$on('someEvent', function(){
// From here we can react anytime there's an event "someEvent" triggered
});
};
});​
Communicating between directives
app.directive('gdayx', function() { // Creating the directive
return {
restrict: 'E', // Restricted to "element"
controller: function($scope) {
$scope.what = "";

// Creating the controller of the directive

// Local data

this.is = function(what) {

// External accessor

$scope.what = what;
}
},
link: function($scope, $element){
$element.bind("click", function() { // Binding on click
alert("GDayX is "+$scope.what); // Getting content from the Controller.
});
}
}
​

});
Communicating between directives
// This directive will "send" data to the first directive
app.directive('is', function() {

// Creating the directive

return {
require: "gdayx",

// Requiring the "gdayx" controller

restrict: 'A',

// Restricting to "attribute"

link: function(scope, element, attrs, gdayxCtrl) {
// gdayxCtrl from the "require: 'gdayx'"
gdayxCtrl.is(attrs.is); // Passing value to the "gdayx" controller
}
}
});​
AngularJS - Why is it awesome?

•
•
•
•
•

Mature, production-ready
Feature-rich
The design and what it allows
Strong support from giants like Google
A lot of solid companies are embracing it
o
o
o

Ebay Commerce Network
DoubleClick (Google) - Marketing Manager & Planner
YouTube APP on PS3
Best Practices

•
•

Organize the code well (Captain Obvious!)
Organize modules by feature

•
•

Use the reusability as much as possible
Use the testability as much as possible

angular.module('users', ['utilities']);
angular.module('groups', ['utilities']);
angular.module('mainApp', ['users', 'groups']);

o
o

TDD
BDD?
Testing, tooling
•
•
•
•
•
•

Yeoman
o Super workflow tool and generator/scaffolder
Batarang
o Chrome Debugger Extension, (A must have), link
Grunt
o Task runner
Bower
o Package Manager for JS Libraries
Protractor, Karma
o Test Runner
Jasmine, Mocha
o Test Frameworks
And SEO?

•

Google "Snapshot" famous technic
o
o

_escaped_fragment_
Turns this:


o

Into this:


•
•

http://prerender.io/getting-started#html5-pushstate
http://prerender.io/getting-started?
_escaped_fragment_=html5-pushstate

prerender.io/ - Open Source project
brombone.com/ - Commercial project
Enterprise project with Angular?

•
•

YES
BUT
Enterprise project with Angular?

•
•

YES
BUT
o
o
o

Follow best practices (easier said than done)
System Architecture is KEY to a solid system
As "Agile" would advise, always try to go for simpler
but "well-thought" "team-friendly"designs.
Enterprise project with Angular?

•

An example Architecture
Backend
(legacy)

A/B t
esting
?

Legacy Front End

Experimental Front
End

DB
Backend
(experimental)

Server-side team realm

Experimental Front
End 2

Front-End team realm
Final Words

•
•

Angular 1.0.x is mature
Angular 1.2+ will bring more awesomeness
o
o

Better and Fluid Animations (js/css3)
More flexibility and functionalities




$interval: add a service wrapping setInterval
Event directives: add ngCopy, ngCut, and ngPaste
jQuery 1.10.x support
DEMO
(if time permits :)
Bootstrapped app

•
•

Let's see a quick Angular App
Bootstrapped from Yeoman
Where you can find me:
Author: Nicolas Embleton @: nicolas.embleton@gmail.com
Presentation made for “Google Developer Day GDayX 2013 Vietnam”
You can follow me at:
https://plus.google.com/+NicolasEmbleton
https://twitter.com/nicolasembleton

•
•

And the Javascript Ho Chi Minh City Meetup:
http://meetup.com/JavaScript-Ho-Chi-Minh-City/
https://www.facebook.com/JavaScriptHCMC
https://plus.google.com/communities/116105314977285194967

•
•
•

o

Our group is looking for Projects to mentor. If you have a project you want support for, contact
me
Resources
Learning
• Learning AngularJS by the example (+60 minutes-ish training video)
• http://www.nganimate.org/
• https://github.com/angular-ui/ui-router
o It's a full "nested-view" library

• http://docs.angularjs.org/guide/dev_guide.templates.databinding
• ng-learn.org
Reusable Components
• http://ngmodules.org/
• http://www.directiv.es/

Weitere ähnliche Inhalte

Was ist angesagt?

Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work EverywhereDoris Chen
 
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next LevelMWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next Levelbalassaitis
 
[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web DesignChristopher Schmitt
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWalter Ebert
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...IT Event
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsJulien Lecomte
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)jeresig
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5dynamis
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
High Performance Django
High Performance DjangoHigh Performance Django
High Performance DjangoDjangoCon2008
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jeresig
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009Ralph Whitbeck
 
Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...CodelyTV
 

Was ist angesagt? (20)

Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work Everywhere
 
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next LevelMWLUG 2015 - AD114 Take Your XPages Development to the Next Level
MWLUG 2015 - AD114 Take Your XPages Development to the Next Level
 
Makezine
MakezineMakezine
Makezine
 
[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFM
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
High-Quality JavaScript
High-Quality JavaScriptHigh-Quality JavaScript
High-Quality JavaScript
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
High Performance Django
High Performance DjangoHigh Performance Django
High Performance Django
 
Gae
GaeGae
Gae
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
Wicket 2010
Wicket 2010Wicket 2010
Wicket 2010
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
 
Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...
 

Andere mochten auch

TDD with KnockoutJS
TDD with KnockoutJSTDD with KnockoutJS
TDD with KnockoutJSKyle Hodgson
 
29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview QuestionsArc & Codementor
 
Advanced AngularJS Concepts
Advanced AngularJS ConceptsAdvanced AngularJS Concepts
Advanced AngularJS ConceptsKyle Hodgson
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTestMark
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 

Andere mochten auch (6)

TDD with KnockoutJS
TDD with KnockoutJSTDD with KnockoutJS
TDD with KnockoutJS
 
Testing AngularJS
Testing AngularJSTesting AngularJS
Testing AngularJS
 
29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
 
Advanced AngularJS Concepts
Advanced AngularJS ConceptsAdvanced AngularJS Concepts
Advanced AngularJS Concepts
 
A Big Look at MiniTest
A Big Look at MiniTestA Big Look at MiniTest
A Big Look at MiniTest
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 

Ähnlich wie gDayX - Advanced angularjs

GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSNicolas Embleton
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
Introduction à AngularJS
Introduction à AngularJSIntroduction à AngularJS
Introduction à AngularJSNicolas PENNEC
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh! Chalermpon Areepong
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinTech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinLeanIX GmbH
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsclimboid
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayAll Things Open
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Againjonknapp
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Doris Chen
 

Ähnlich wie gDayX - Advanced angularjs (20)

GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JS
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Introduction à AngularJS
Introduction à AngularJSIntroduction à AngularJS
Introduction à AngularJS
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinTech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Angularjs
AngularjsAngularjs
Angularjs
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!
 

Kürzlich hochgeladen

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

gDayX - Advanced angularjs

  • 2. About me Nicolas Embleton, French in Ho Chi Minh City • • • • 2005 - Software Engineer and System Architect, working on legacy tech stacks (C++, OpenGL, Java, ...) then quickly Web (PHP) 2009 - Founded a Mobile Development Company of 30 individuals 2011 - Started Datafield Startup, Co-founder, CTO 2013 - Started the Javascript Ho Chi Minh City meetup, Getting active in Startup Vietnamese scene to support and mentor young talents
  • 3. Agenda • • • • • • • • Quick Intro Bootstrapping Why Angular? Main features, and why it's awesome Best practices Testing, tooling And SEO? Final words
  • 4. Intro (quick) From Wikipedia: AngularJS is built around the belief that declarative programming should be used for building UIs and wiring software components, while imperative programming is excellent for expressing business logic. The framework adapts and extends traditional HTML to better serve dynamic content through two-way data-binding that allows for the automatic synchronization of models and views. As a result, AngularJS deemphasizes DOM manipulation and improves testability.
  • 5. Angular JS quick review • • • • • • • Templating Model View Controller (MVC) Extends HTML (very flexible) 2-ways Data-binding Very reusable (if you follow best practices) Improves testability (because it is reusable) Provides routing, history, jqLite, ...
  • 6. Bootstrapping • Using angular-seeds • Using yeoman (excellent workflow tool) o git clone https://github.com/angular/angular-seed.git o node scripts/web-server.js o open http://localhost:8000/app/index.html o o o o o (sudo) npm install -g yo (sudo) npm install -g generator-angular yo angular bower install angular-ui grunt server
  • 7. Now, the meat, the main features • • • • • • Templating Routing 2-ways data-binding Directives, services Dependency Injection Inter-components Communication
  • 8. Templating • Models • Built-in directives 2-way binding o Easy property mapping o ngView  Where the routing happens o ngRepeat  Iterator o ngIf o ngSwitch o
  • 9. Templating - Conditional with ngIf <div ng-repeat="message in data.messages" ng-class="message.type"> <hr> <div ng-if="showFrom(message)"> <div>From: {{message.from.name}}</div> </div> <div ng-if="showCreatedBy(message)"> <div>Created by: {{message.createdBy.name}}</div> </div> <div ng-if="showTo(message)"> <div>To: {{message.to.name}}</div> </div> </div>​
  • 10. Templating - Nested repeat <div ng-repeat="group in groups"><!-- 1st ng-repeat level --> <h2>{{ group.label }}</h2> <ul> <li ng-repeat="friend in group.friends"> <!-- 2nd ng-repeat level --> {{ friend.name }} </li> </ul><!-- END: Inner ngRepeat. --> </div><!-- END: Outer ngRepeat. -->​
  • 11. Templating - Example 2 - Switch <div ng-switch on="selection" > <div ng-switch-when="settings">Settings Div</div> <span ng-switch-when="home">Home Span</span> <span ng-switch-default>default</span> </div>​
  • 12. Example 2.2 - Switch with 2-way bind <div ng-controller="Ctrl"> <select ng-model="selection" ng-options="item for item in items"> </select> <tt>selection={{selection}}</tt> <hr/> <div class="animate-switch-container" ng-switch on="selection"> <div ng-switch-when="settings">Settings Div</div> <div ng-switch-when="home">Home Span</div> <div ng-switch-default>default</div> </div> </div>
  • 13. Templating - Simple ngRepeat <li ng-repeat="item in items"> Item: {{ item }} </li>
  • 14. Templating - Complex ngRepeat <header ng-repeat-start="item in items"> Header {{ item }} </header> <div class="body"> Body {{ item }} </div> <footer ng-repeat-end> Footer {{ item }} </footer>
  • 15. Compiling // compile the new DOM and link it to the current scope. // NOTE: we only compile .childNodes so that // we don't get into infinite loop compiling ourselves $compile(element.contents())(scope);
  • 16. Templating - Routing • • • • Happens in ngView Routing is a very powerful feature Allows to update "pieces" of the page Can stream files from disk to make it truly isolated
  • 17. 2-ways data-binding • • • • Becoming more standard, thanks to frameworks like Ember.js or Angular.js • Example Linking 2 fields for synchronization purpose Linking data to model Automatically updating the template as data is changed o Arrays / Collections o Inputs o etc…
  • 18. 2-ways data-binding, example <input type="text" ng-model="title" style="width: 90%"/> <div ng-app="myapp"> <div ng-controller="mycontroller"> Title: {{ title }} <!-- 2-way data binding --> <hr> <div class="zippy" zippy-title="title"></div> </div> </div>​
  • 19. Directives • • • Angular.js killer feature Great deal of re-usability Just look for directives at ngmodules.org
  • 20. Restricting Directives • • • • • "E": Element, <my-directive> "A": Attribute, <div my-directive> "C": Class, <div class="my-directive"> "M": Comment: <!-- directive: my-directive exp --> Combine (e.g. "EA") for more flexibility
  • 21. Communicating between directives • • Many design patterns The "backbonier" • A more connected example o o the emitter and the receiver the directive combinations and controller sharing
  • 22. Communicating between directives app.directive('directiveA', function($rootScope){ return function(scope, element, attrs) { // $rootScope = App Scope // scope = Current scope (ctrl) $rootScope.$on('someEvent', function(){ // From here we can react anytime there's an event "someEvent" triggered }); }; });​
  • 23. Communicating between directives app.directive('gdayx', function() { // Creating the directive return { restrict: 'E', // Restricted to "element" controller: function($scope) { $scope.what = ""; // Creating the controller of the directive // Local data this.is = function(what) { // External accessor $scope.what = what; } }, link: function($scope, $element){ $element.bind("click", function() { // Binding on click alert("GDayX is "+$scope.what); // Getting content from the Controller. }); } } ​ });
  • 24. Communicating between directives // This directive will "send" data to the first directive app.directive('is', function() { // Creating the directive return { require: "gdayx", // Requiring the "gdayx" controller restrict: 'A', // Restricting to "attribute" link: function(scope, element, attrs, gdayxCtrl) { // gdayxCtrl from the "require: 'gdayx'" gdayxCtrl.is(attrs.is); // Passing value to the "gdayx" controller } } });​
  • 25. AngularJS - Why is it awesome? • • • • • Mature, production-ready Feature-rich The design and what it allows Strong support from giants like Google A lot of solid companies are embracing it o o o Ebay Commerce Network DoubleClick (Google) - Marketing Manager & Planner YouTube APP on PS3
  • 26. Best Practices • • Organize the code well (Captain Obvious!) Organize modules by feature • • Use the reusability as much as possible Use the testability as much as possible angular.module('users', ['utilities']); angular.module('groups', ['utilities']); angular.module('mainApp', ['users', 'groups']); o o TDD BDD?
  • 27. Testing, tooling • • • • • • Yeoman o Super workflow tool and generator/scaffolder Batarang o Chrome Debugger Extension, (A must have), link Grunt o Task runner Bower o Package Manager for JS Libraries Protractor, Karma o Test Runner Jasmine, Mocha o Test Frameworks
  • 28. And SEO? • Google "Snapshot" famous technic o o _escaped_fragment_ Turns this:  o Into this:  • • http://prerender.io/getting-started#html5-pushstate http://prerender.io/getting-started? _escaped_fragment_=html5-pushstate prerender.io/ - Open Source project brombone.com/ - Commercial project
  • 29. Enterprise project with Angular? • • YES BUT
  • 30. Enterprise project with Angular? • • YES BUT o o o Follow best practices (easier said than done) System Architecture is KEY to a solid system As "Agile" would advise, always try to go for simpler but "well-thought" "team-friendly"designs.
  • 31. Enterprise project with Angular? • An example Architecture Backend (legacy) A/B t esting ? Legacy Front End Experimental Front End DB Backend (experimental) Server-side team realm Experimental Front End 2 Front-End team realm
  • 32. Final Words • • Angular 1.0.x is mature Angular 1.2+ will bring more awesomeness o o Better and Fluid Animations (js/css3) More flexibility and functionalities    $interval: add a service wrapping setInterval Event directives: add ngCopy, ngCut, and ngPaste jQuery 1.10.x support
  • 34. Bootstrapped app • • Let's see a quick Angular App Bootstrapped from Yeoman
  • 35. Where you can find me: Author: Nicolas Embleton @: nicolas.embleton@gmail.com Presentation made for “Google Developer Day GDayX 2013 Vietnam” You can follow me at: https://plus.google.com/+NicolasEmbleton https://twitter.com/nicolasembleton • • And the Javascript Ho Chi Minh City Meetup: http://meetup.com/JavaScript-Ho-Chi-Minh-City/ https://www.facebook.com/JavaScriptHCMC https://plus.google.com/communities/116105314977285194967 • • • o Our group is looking for Projects to mentor. If you have a project you want support for, contact me
  • 36. Resources Learning • Learning AngularJS by the example (+60 minutes-ish training video) • http://www.nganimate.org/ • https://github.com/angular-ui/ui-router o It's a full "nested-view" library • http://docs.angularjs.org/guide/dev_guide.templates.databinding • ng-learn.org Reusable Components • http://ngmodules.org/ • http://www.directiv.es/