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
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 databinding 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
o git clone https://github.com/angular/angular-seed.git
o node scripts/web-server.js
o open http://localhost:8000/app/index.html
•
Using yeoman (excellent workflow tool)
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
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>
21. Communicating between directives
•
•
Many design patterns
The "backbonier"
o
•
the emitter and the receiver
A more connected example
o
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 = "";
this.is = function(what) {
// Creating the controller of the directive
// Local data
// 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
angular.module('users', ['utilities']);
angular.module('groups', ['utilities']);
angular.module('mainApp', ['users', 'groups']);
•
•
Use the reusability as much as possible
Use the testability as much as possible
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
o
•
•
_escaped_fragment_
Turns this:
http://prerender.io/getting-started#html5-pushstate
Into this:
http://prerender.io/getting-started?_escaped_fragment_=html5pushstate
prerender.io/ - Open Source project
brombone.com/ - Commercial project
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
Legacy Front End
Backend
(legacy)
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
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://docs.angularjs.org/guide/dev_guide.templates.databinding
http://www.nganimate.org/
https://github.com/angular-ui/ui-router
o It's a full "nested-view" library
ng-learn.org
Reusable Components
•
•
http://ngmodules.org/
http://www.directiv.es/