170 likes | 336 Views
Design Principles of . Mi š ko Hevery Father of AngularJS. The Principles. Boilerplate. D.R.Y. Structure. Testability. 2009: GetAngular. <angular/>. Results. Project. 17,000 LOC. 1,500 LOC. Before. with Angular. <div>. <span>. <ul>. RAM. <li>. <li>. <li>. Database.
E N D
Design Principles of Miško Hevery Father of AngularJS
The Principles Boilerplate D.R.Y. Structure Testability
2009: GetAngular <angular/>
Results Project 17,000 LOC 1,500 LOC Before with Angular
<div> <span> <ul> RAM <li> <li> <li> Database
Data Binding Eureka: DOM <html ng-app> <body> <input ng-model='user.name'> <p ng-show='user.name'>Hi {{user.name}}</p> <script src='angular.js'></script> </body> </html>
{{ databinding }} <div> <span> <ul> RAM <li> <li> <li> Logic
<htmlng-app> <body ng-controller='UserCtrl as uCtrl'> Hi<input ng-model='uCtrl.user.first'> <button ng-click='uCtrl.bye()'>bye</button> <script src='angular.js'></script> <script src='UserControllers.js'></script> </body> </html> MVC function UserCtrl() { this.user = { first:'Larry', last:'Page' }; this.bye = function() { alert('bye:' + this.user.first); }; } index.html UserController.js
Structure Data / Model (JS Objects) UI / View (DOM) Observes <div> RAM <span> <ul> <li> Manages Notifies Logic / Controller (JS Classes)
Dependency Injection Module: myApp functionUserController(voiceSynth) { this.user = { first:'Larry', last: 'Page' }; this.bye = function() { voiceSynth.say('bye') }; } functionVoiceSynth(webAudio) { this.say = function(text) {// do Web Audio stuff}; }; var myApp = angular.module('myApp', []); myApp.controller('UserController', UserController); myApp.service('voiceSynth', VoiceSynth); View (DOM) UserController VoiceSynth WebAudio
Dependency Injection: Mocking Module: myMocks -> myApp functionVoiceSynthMock() { this.say = function(text) { this.said.push(text); }; this.said = []; }; var myMocks = angular.module('myMocks', ['myApp']); myApp.service('voiceSynth', VoiceSynthMock); View (DOM) UserController VoiceSynth VoiceSynthMock WebAudio
Imperative Declarative {{ databinding }} ng-hide ng-controller ng-model Eureka!!! my-tab my-pane my-map
<tabs> <tab title="Active tab">...</tab> <tab title="Inactive tab">...</tab> </tabs> <span tooltip="{{messages.tip1}}"> Directives as Components <rating max="5" model="stars.average"> </rating>
Ecosystem Tools UI Components Libraries Books Batarang AngularUI
Code samples: http://goo.gl/N1sCd Thank You! angularjs.org +angularjs @angularjs @mhevery