Name: "> Name: ">
Download presentation
Presentation is loading. Please wait.
Published byLilly Waye Modified over 9 years ago
1
Richard Johnson Goal Designs Inc. Minnesota Web Design Meetup – April 15, 2013 Slides available: http://goaldesigns.com/presentations-2013http://goaldesigns.com/presentations-2013 rjohnson@goaldesigns.com
2
Web designed for documents Server creates pages / browser displays Data input sent to and processed by the server Updated pages created on the server and resent
3
Name: <?php echo " Hello ".$HTTP_POST_VARS["yourName"]."! "; ?> Name: <?php echo " Hello ".$HTTP_POST_VARS["yourName"]."! "; ?>
4
Interactive client-side web Collect input from user Update display Communicate with server Client-side processing enabled by JavaScript DOM manipulation HTTP server messaging
5
$(function() { $("#yourName").keyup(function () { $("#helloName").text("Hello " + this.value + "!"); }); Name: $(function() { $("#yourName").keyup(function () { $("#helloName").text("Hello " + this.value + "!"); }); Name:
6
Simplifies event binding and DOM manipulation Common API across multiple browsers Supports plug-in modules to extend functionality Requires writing JavaScript code to wire
7
Follow good programming practices Separate: data / display / processing Simplify connecting data to display Let us focus on the technologies of the web HTML CSS JavaScript
8
<script src="https://ajax.googleapis.com/ajax/libs/ angularjs/1.0.6/angular.min.js"> Name: Hello {{yourName}}! <script src="https://ajax.googleapis.com/ajax/libs/ angularjs/1.0.6/angular.min.js"> Name: Hello {{yourName}}!
9
Compare jQuery imperative wiring to AngularJS declarative relationships Hello {{yourName}}! Hello {{yourName}}! $(function() { $("#yourName").keyup(function () { $("#helloName").text("Hello " + this.value + "!"); }); $(function() { $("#yourName").keyup(function () { $("#helloName").text("Hello " + this.value + "!"); });
10
jQuery abstracts browser functionality e.g. DOM traversal, event binding AngularJS abstracts relationships (and more) Note: AngularJS, and all web apps, are built on browser functionality
11
HTML is a declarative document language Browser translates HTML into a Document Object Model (DOM) DOM is the browser’s in-memory document representation JavaScript can manipulate the DOM
12
Browsers send a document (i.e. DOM) ready event AngularJS can intercede and rewrite the DOM The rewrite is driven by markup in the DOM
13
Software architectural pattern Separates display from data Originated with Smalltalk programmers From work at Xerox PARC in the late 70’swork at Xerox PARC Models represent knowledge Views provide a (visual) representation of attached model data Controllers connect to and control views and models
14
Different variations of the pattern Model-View-ViewModel (MVVM) Model-View-Presenter (MVP) Variations differ on… … connectivity … cardinality … directionality
15
“MVC vs MVVM vs MVP. What a controversial topic that many developers can spend hours and hours debating and arguing about. For several years AngularJS was closer to MVC (or rather one of its client- side variants), but over time and thanks to many refactorings and api improvements, it's now closer to MVVM – the $scope object could be considered the ViewModel that is being decorated by a function that we call a Controller. … I hereby declare AngularJS to be MVW framework - Model-View- Whatever. …” Igor Minar – Google AngularJS Development Team
16
Backbone.js Backbone.js Ember.js Ember.js Knockout Knockout Others Summary from 2012 Throne of JS conference2012 Throne of JS conference
17
Library (Backbone and Knockout) passive functionality invoked by the application Framework (Ember) provides application architecture handles common requirements invokes application code AngularJS is closer to a framework
19
*I ported my Backbone application to angular. The Code size went down from 5k lines of code to guess what? 750 lines. Not just that.. The code is much cleaner.. Earlier, there was a huge technical debt attached to this implementation in backbone.. Each time I had to sit with it. It took me quite a while to understand all the hooks and how the individual models and classes and views interacted together....Now its a breeze.. * http://stackoverflow.com/a/10264263 http://stackoverflow.com/a/10264263
20
Working with AJAX in mid-2011 XML for data XSLT to map XML data to HTML Considered changing to JSON Found a link to AngularJS (alpha)
21
AngularJS website: angularjs.organgularjs.org Examples are live Phonecat tutorial is worthwhile My “goto” sources: Developer guide API reference
22
Load AngularJS <script src="https://ajax.googleapis.com/ajax/libs/ angularjs/1.0.6/angular.min.js"> Bootstrap Declare relationships ng-model="yourName” {{yourName}}
23
One created with each controller Prototypically inherits from parent AngularJS has a root scope Can create isolated scopes (e.g. in directive)
26
Automatic propagation of data changes Model is single source of truth Digest cycle
27
Contains the code behind the view Try to keep lightweight
28
Added to a WordPress site Custom theme Page templates with shortcodes Built summer 2012 (just as AngularJS 1.0 shipped) Created order form and product location pagesorder form product location Note – it’s a live site (and good wine ) Too much code in the controller - modularize
29
Provides declarative form validation Input fields declared as: required, email Form has flags for: $valid, $dirty Usable as a standalone validation library
30
Directives enhance HTML Custom element name or attribute (also class and comment) AngularJS provides over 50 form – element directive ng-repeat – attribute directive (it’s amazing!) ng-repeat
31
Declarative way to format displayed data format filter and sort data arrays filter sort
32
Software architectural components Services provide data and compute Exist across views Depend on other services AngularJS has 20+ $http – service to communicate with servers $http
33
$http service Input config object Returns promise Communication is asynchronous $http({method: ‘GET’, url: fetchUrl}).success(function(data, status) { // process the data here }).error(function(data, status) { // error handling }); $http({method: ‘GET’, url: fetchUrl}).success(function(data, status) { // process the data here }).error(function(data, status) { // error handling });
34
Promises represent result of an action Promises Particularly used with asynchronous actions They are either resolved or rejected
35
DI is a software architectural pattern Separation of concerns Service creation independent from usage Good for Modular code Allows AngularJS to wire in correct order Supports substitution (for patching and testing)
36
Services identified by parameter name Minification obfuscates the name Pass names as strings in array angular.module('GoaleryServices').factory('StatusManager', [ 'CloudLogin', '$q', function (cloudLogin, $q) { … angular.module('GoaleryServices').factory('StatusManager', [ 'CloudLogin', '$q', function (cloudLogin, $q) { …
37
Prototype-based scripting language Dynamic, weakly typed, first-class functions Great JavaScript book: Crockford (2008) JavaScript: The Good Parts – O’Reilly
38
JavaScript doesn’t have a compiler Must execute code to test Testability was a fundamental objective of AngularJS Miško Hevery (AngularJS creator) Previously created JsTestDriver
39
Unit testing support Unit testing JsTestDriver Jasmine DI allows substituting mocks for hard to test code Server communication Logging Angular Scenario Runner – E2E testingE2E testing Simulates user interations
40
Single web page Loads the base HTML and included sources once App changes views dynamically Server is called upon when needed Prefer using asynchronous server calls Data changes Fetch more data
41
Declarative view specification HTML augmented with: Directives, Markup, Filter, Form Controls Loaded either with a simple single web page dynamically into a view as partialsview
42
Define the mapping from URL to view Can also bind controller Define URL parameters $routeProvider.when('/Book/:bookId', { templateUrl: 'book.html', controller: BookCntl }); $routeProvider.when('/Book/:bookId/ch/:chapterId', { templateUrl: 'chapter.html', controller: ChapterCntl }); $routeProvider.when('/Book/:bookId', { templateUrl: 'book.html', controller: BookCntl }); $routeProvider.when('/Book/:bookId/ch/:chapterId', { templateUrl: 'chapter.html', controller: ChapterCntl });
43
AngularJS navigation updates the browser address bar Uses the HTML5 history API – fallback to hash-bang (#!) URL Users can link to pages in you app Server must recognize the link pattern and serve the application
44
Directives package reusable HTML Directives Naming nuance: “myDir” becomes “my-dir” Conceptual compile and link phases Can specify: scope, binding, restrictions, etc Supports transclusion Consider creating a custom DSL
45
Packaging of JavaScript code Modules declare dependencies Modules AngularJS instantiates in correct order Provides separation of namespaces
46
Open source – MIT License Built by Google and community 1.0 released June 2012 1.0.6 current (April 2013) http://angularjs.org/ http://angularjs.org/
47
AngularJS 1.0.X are considered stable production releases Contains bug fixes and documentation updates AngularJS 1.1.X is unstable development Next stable feature release will be 1.2.X Available on the Google CDN https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angul ar.js https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angul ar.js Both full source and minified (angular.min.js)
48
AngularJS includes a jQuery “lite” Provides the minimal features directly used Including jQuery will be used instead Note – jQuery must be included before AngularJS
49
Chrome Internet Explorer 9+ (others see next slide) Firefox Safari Opera mobile browsers (Android, Chrome Mobile, iOS Safari)
50
IE 8 is officially supported and tested Declare custom element tags Routing uses #! mode (IE9 also has no HTML 5 history) A few other XML namespace declarations See http://docs.angularjs.org/guide/iehttp://docs.angularjs.org/guide/ie IE 6 & 7 support is possible “in theory” Google doesn’t test these versions < 1% of U.S. browsers (March 2013)
51
Chrome debugger plugin Jasmine testing framework plugin
52
AngularJS UI – https://github.com/angular-uihttps://github.com/angular-ui Compilation of several projects ▪ AngularJS UI – calendar, date, map, if ▪ UI Bootstrap – Twitter bootstrap components ▪ ng-grid – data grid ▪ UI-Router – enhanced routing with UI states AngularStrap - http://mgcrea.github.io/angular- strap/http://mgcrea.github.io/angular- strap/
53
Blog – official announcments Blog Forums – support Forums JSFiddle Examples JSFiddle Examples Cheat Sheet Cheat Sheet
54
AngularJS (April 29, 2013) Green & Seshadri – O’Reilly AngularJS in Action (Fall 2013) Ford & Ruebbelke– Manning
55
Coding in Angular http://www.egghead.io/ http://www.egghead.io/ Front-end Masters Front-end Masters AngularJS &Testability – Misko Hevery Javascript the Good Parts – Douglas Crockford
56
Animation support More flexible (and faster) ngRepeat directive Powerful promise-based http request interceptors Dynamically generated directive templates Initial batch of mobile/touch support
57
“What a web browser would have been had it been designed for web applications” - Miško Hevery Upcoming AngularJS presentation Google Developer Group – Twin Cities May 1, 2013 at CoCo May 1, 2013 at CoCo
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.