angular js is the future. maybe. @ confoo 2014 in montreal (ca)

143
AngularJS is the future Alessandro Nadalin - Montreal, February 2014

Upload: alessandro-nadalin

Post on 08-May-2015

4.282 views

Category:

Technology


0 download

DESCRIPTION

Since bumping into AngularJS a few months ago, we decided to invest more and more time developing with it: coming from a PHP background, the shift of paradigm easy due to the use of patterns and intuitive flows: even though this won’t be a very in-depth technical talk, we are going to see why you should consider working with angular: fast single-page apps, DI, ease of testing, being asynchronous, scaling on the clients. Welcome to the future.

TRANSCRIPT

Page 1: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

AngularJS is the futureAlessandro Nadalin - Montreal, February 2014

Page 2: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

AngularJS

Page 3: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 4: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

2009

Page 5: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

SPA

Page 6: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

example.org/#!/about

Page 7: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 8: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

history.pushState(...)

Page 9: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 10: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Killer Features

Page 11: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Killer Features2-way data binding

Page 12: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Model changes the View

Page 13: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

View changes the Model

Page 14: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 15: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

http://jsfiddle.net/WLUPj/2/

Page 16: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope) { $scope.title = 'Lorem Ipsum';}

Page 17: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="zippyModule"> <div ng-controller="Ctrl"> Title: <input ng-model="title"> <hr> <div data-zippy="title"></div> </div></div>

Page 18: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="zippyModule"> <div ng-controller="Ctrl"> Title: <input ng-model="title"> <hr> <div data-zippy="title"></div> </div></div>

Page 19: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="zippyModule"> <div ng-controller="Ctrl"> Title: <input ng-model="title"> <hr> <div data-zippy="title"></div> </div></div>

Page 20: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope) { $scope.title = 'Lorem Ipsum';}

Page 21: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="zippyModule"> <div ng-controller="Ctrl"> Title: <input ng-model="title"> <hr> <div data-zippy="title"></div> </div></div>

Page 22: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope) { $scope.title = 'Lorem Ipsum';}

Title: <input ng-model="title">

Page 23: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope) { $scope.title = 'Lorem Ipsum';}

Title: <input ng-model="title">

Page 24: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="zippyModule"> <div ng-controller="Ctrl"> Title: <input ng-model="title"> <hr> <div data-zippy="title"></div> </div></div>

Page 25: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

directive('zippy', function(){return {

restrict: 'A',replace: true,scope: {

title:'=zippy'},template: '<input type="text" ng-model="title" />'

}}

Page 26: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

directive('zippy', function(){return {

restrict: 'A',replace: true,scope: {

title:'=zippy'},template: '<input type="text" ng-model="title" />'

}}

Page 27: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

directive('zippy', function(){return {

restrict: 'A',replace: true,scope: {

title:'=zippy'},template: '<input type="text" ng-model="title" />'

}}

Page 28: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 29: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

http://docs.angularjs.org/guide/databinding

Page 30: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Killer FeaturesDependency Injection

Page 31: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope) { // WHAT THE HECK SHALL I DO HERE???}

Page 32: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope, $location) { // WHAT THE HECK SHALL I DO HERE???}

Page 33: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope, $location) { // WHAT THE HECK SHALL I DO HERE???}

Page 34: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

function Ctrl($scope, $location) { $scope.whereAmI = $location.host();}

Page 35: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 36: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 37: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

http://jsfiddle.net/9J7u5/2/

Page 38: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Killer FeaturesSupport

Page 39: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 40: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 41: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 42: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 43: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 44: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 45: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 46: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

https://github.com/angular/protractor

Page 47: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Killer FeaturesDirectives

Page 48: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <menu /> </div></div>

Page 49: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <menu /> </div></div>

Page 50: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <div menu></div> </div></div>

Page 51: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <div data-menu></div> </div></div>

Page 52: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

var links = { home: { link: 'http://example.com', title: 'Home' }, about: { link: 'http://example.com/about', title: 'About Us' }};

Page 53: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

var links = { home: { link: 'http://example.com', title: 'Home' }, about: { link: 'http://example.com/about', title: 'About Us' }};

Page 54: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 55: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 56: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 57: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 58: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 59: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 60: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 61: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <menu /> </div></div>

Page 62: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 63: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 64: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <div data-menu /> </div></div>

Page 65: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 66: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<div ng-app="confoo"> <div ng-controller="Ctrl"> <menu /> </div></div>

Page 67: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 68: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 69: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 70: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 71: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

angular.module('confoo', []) .directive('menu', function(){ return { restrict: 'AE', scope: {}, template: ‘path/to/tpl.html’, link: function (scope) { scope.items = links; } } });

Page 72: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<body ng-app="confoo"><confoo-header><div><div ng-controller=”MainCtrl”><confoo-sidebar>

</div><confoo-footer>

</div>

Page 73: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<body ng-app="confoo"><confoo-header><div><div ng-controller=”MainCtrl”><confoo-sidebar>

</div><confoo-footer>

</div>

Page 74: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<body ng-app="confoo"><confoo-header><div><div ng-controller=”MainCtrl”><confoo-sidebar>

</div><confoo-footer>

</div>

Page 75: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<body ng-app="confoo"><confoo-header><div><div confoo-main-content><confoo-sidebar>

</div><confoo-footer>

</div>

Page 76: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

http://jsfiddle.net/Lj6CH/6/

Page 77: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

“Controllers, Directives and Services” http://is.gd/QlGYID

Page 78: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

and much much more :)

Page 79: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Why do we like AngularJS?

Page 80: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Solid and clear foundation

Page 81: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Solid and clear foundation

$routeProvider.when(‘/about’, {templateUrl: '/views/about.html',controller: 'AboutController',

});

Page 82: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Solid and clear foundation

$http({ method: 'GET', url: '/milk.html }).success(function(...) {

alert(‘YEAH!’);}).error(function(...) {

alert(‘AWWW, SNAP!’);});

Page 83: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Works well with the JS ecosystem

Page 84: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Works well with the JS ecosystem

Page 85: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

.container(data-bindonce).row

#my-whateverp {{ myModel.text }}

Works well with the JS ecosystem

Page 86: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

.container(data-bindonce).row

#my-whateverinput(ng-model=”myModel”)

Works well with the JS ecosystem

Page 87: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Modern API-oriented architectures

Page 88: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

APIfy everything

Page 89: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 90: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Easier to scale

Page 91: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

No sessions on the servers

Page 92: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

mantain state on the client (LS)

Page 93: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

What will you hateabout AngularJS?

Page 94: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

ehm...

Page 95: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

https://www.destroyallsoftware.com/talks/wat

Page 96: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Watchers

Page 97: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

lotsa bindings, lotsa watchers

Page 98: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

lotsa watchers, lotsa computation

Page 99: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

Page 100: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

prepare for N...

Page 101: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

N * 1

Page 102: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items"> <a href="{{ item.link }}"> {{ item.title }} </a> </li></ul>

N * 2

Page 103: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 104: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items">

<a href="{{ item.link }}">{{ item.title }}<menu

ng-if=”item.links”links=”item.links”

/></a>

</li></ul>

Page 105: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

<ul> <li ng-repeat="item in items">

<a href="{{ item.link }}">{{ item.title }}<menu

ng-if=”item.links”links=”item.links”

/></a>

</li></ul>

Page 106: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

use 1-way data binding if possible

Page 107: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

https://github.com/Pasvaz/bindonce

Page 108: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

try to stay under ~800 watchers

Page 109: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

UI screws for realat ~2000

;-)

Page 110: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

ehm...

Page 111: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

but also…

Page 112: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 113: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

memory, rendering, ...

Page 114: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

they don’t just render anymore

Page 115: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

The browser is your platform

Page 116: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

and the VM on whichyour application runs

Page 117: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

is implemented in different ways, based on the browsers themselves

Page 118: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Page 119: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Is AngularJS the future?

Page 120: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Maybe.

Page 121: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Or, I mean...

Page 122: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

We will still need backends

Page 123: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

or use WP a lot ;-)

Page 124: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

but

Page 125: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Natural evolution, decoupled apps

Page 126: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Handy solution for some scenarios

Page 127: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

It is a future

Page 128: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Javascript Frameworks And Data Bindinghttp://tunein.yap.tv/javascript/2012/06/11/javascript-frameworks-and-data-binding/

Angular, Backbone, CanJS and Emberhttp://sporto.github.io/blog/2013/04/12/comparison-angular-backbone-can-ember/

Page 129: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

...yawn...

Page 130: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Alessandro Nadalin

Page 131: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Alessandro Nadalin

@_odino_

Page 132: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Alessandro Nadalin

@_odino_

Namshi | Rocket Internet

Page 133: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Alessandro Nadalin

@_odino_

Namshi | Rocket Internet

VP Technology

Page 134: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Alessandro Nadalin

@_odino_

Namshi | Rocket Internet

VP Technology

odino.org

Page 135: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Thanks!Alessandro Nadalin

@_odino_

Namshi | Rocket Internet

VP Technology

odino.org

Page 136: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

By the way

Page 137: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Wanna join?

Page 138: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

We are looking for talented nerds!

Page 139: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

frontend engineer

We are looking for talented nerds!

Page 140: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

frontend engineer

We are looking for talented nerds!

data engineer

Page 141: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

lead frontend engineer

We are looking for talented nerds!

data engineer

Page 142: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Thanks!Alessandro Nadalin

@_odino_

Namshi | Rocket Internet

VP Technology

odino.org

Page 143: Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)

Image credits

https://www.flickr.com/photos/santheo/374630020/sizes/l/http://www.flickr.com/photos/spunkinator/3050946547/sizes/o/in/photostream/

https://www.flickr.com/photos/savidgefamily/6873109431/sizes/l/https://www.flickr.com/photos/safari_vacation/7496765660/sizes/o/

https://www.flickr.com/photos/fensterbme/439758782/sizes/l/https://www.flickr.com/photos/dkrape/5154684383/sizes/l/

https://www.flickr.com/photos/kingstongal/2101194332/sizes/o/https://www.flickr.com/photos/thescott365/3186150930/sizes/l/