45
AngularJS How to code today with tomorrow tools Carlo Bonamico - @carlobonamico NIS s.r.l. [email protected] [email protected] Web Framework

AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Embed Size (px)

DESCRIPTION

Many popular online services have demonstrated the power of javascript, html5 and mobile technologies. However, designing, implementing & maintaining a rich application for both web and mobile browsers is a challenging task given the characteristics of javascript. We will share our real-world experience with AngularJS – an open source, robust and brilliantly usable tool which will make your app mobile and designer-friendly, extremely modular and reusable (with Dependency Injection!), and even easily testable (in javascript!), in less than half the code. Expect few slides and lots of code samples and tips from our project experiences. References: http://mozilla.github.io/brick/docs.html http://www.polymer-project.org/ If the hundred year language (from 2113) were available today, would we want to program in it? Paul Graham http://paulgraham.com/hundred.html Enter AngularJS http://www.angularjs.org And almost transparently upgrade as soon as they are available http://www.2ality.com/2013/05/web-components-angular-ember.html Play with AngularJS online Thanks http://plnkr.co So get your training! Codemotion training (4-5 february and 4-5 march 2014) http://training.codemotion.it/ To learn more Online tutorials and video trainings: http://www.yearofmoo.com/ http://egghead.io All links and reference from my Codemotion Workshop https://github.com/carlobonamico/angularjs-quickstart https://github.com/carlobonamico/angularjs-quickstart/blob/master/references.md Full lab from my Codemotion Workshop https://github.com/carlobonamico/angularjs-quickstart Web Components http://www.w3.org/TR/components-intro Youtube video "Web Components in Action" http://css-tricks.com/modular-future-web-components Books http://www.ng-book.com AngularJS and .NET http://henriquat.re My current plans integrate AngularJS with my favourite Open Source server-side dev platform http://www.manydesigns.com/en/portofino Thank you! Explore these slides https://github.com/carlobonamico/angularjs-future-web-development-slides My presentations http://slideshare.net/carlo.bonamico https://twitter.com/carlobonamico

Citation preview

Page 1: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

AngularJS

HowtocodetodaywithtomorrowtoolsCarloBonamico-@carlobonamico

[email protected]@nispro.it

WebFramework

Page 2: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Sure?peopleusedtothinkitwasimpossibletogetinteractiveemailclients(GMail)wordprocessorsandspreadsheets(GDocs)fileshare(Dropbox)real-timemonitoring(Kibana)offlineapps(Nozbe)

Thewebis(andwillalwaysbe)morepowerfulthanpeoplethink!thesamenowappliestomobileweb

whichwillovercomethe"desktop"webintermsoftrafficnextyear

Yesbutyoucan'tdothatinawebapp

Page 3: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

toimplementmynextgreatservice/project...afewmonthsgoby...

WTF!!Ididnotthinkwebdevelopmentwascouldbethatmessy!SpaghetticodetastesbetterinadynamiclanguagesuchasJSIspentmostofmytimejugglingtheDOMIcannotintegratetheFormwidgetsIlovewiththechartslibraryIloveWhereismodularization?andencapsulation?

"everything"canfiddlewith"everything"...

OK,woIwillgoforHTML5

Page 4: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Initially,it"feels"moreproductive,but...Whentheappgrows,

debugginggetsharderrefactoringgetshardereffectivetestinggetsimpossible

Whentheteamgrows,collaborationbecomesharder!everytimeadesignermakesabeautifullook,wespenddaysimplementingitandregressiontesting

It'sbecomingimpossibletoevolve!

Thentheproblemsbegin

Page 5: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Please,beforeIgobacktoDesktopdevelopment,canyoutellmeifthereisabetterway?

HELPME!

Page 6: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Almostanobrainer:goforAdobeFlex!Ithas

encapsulation,interfaceseventdrivenGUImodularandreusablecomoponentsgreattooling

Thewebplatformwasjustnotthereyet...

IfIweretoanswerthisquestionin2008...

Page 7: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Definitelyano-brainer:

goforWebComponents+event-drivenMVChttp://mozilla.github.io/brick/docs.htmlhttp://www.polymer-project.org/

Fast-forwardto2015...

Page 8: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Blurrysituation...

AdobeFlexisOpenSource(butmaybetoolate...)andlostsupportHTML5isbooming,butlarge-scaleJSdevishard

Butplease,IHAVEtodeliveragreatWebAppinafewmonths!

Andnow?onendof2013

Page 9: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Thefutureisalreadyhere—it'sjustnotveryevenlydistributed.WilliamGibson

Ifthehundredyearlanguage(from2113)wereavailabletoday,wouldwewanttoprograminit?

PaulGraham-http://paulgraham.com/hundred.html

Well..

Page 10: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Usetomorrowwebtechnologiestoday

http://www.angularjs.org

Andalmosttransparentlyupgradeassoonastheyareavailablehttp://www.2ality.com/2013/05/web-components-angular-ember.html

EnterAngularJS

Page 11: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

OpenSourcetoolsetbackedbyGoogle

great,activeandopencommunity

usedfromstartupstoMicrosoft,Oracle&Googleitself

Extremelyproductive,robust,testable,andscalablefrommockupstosmallappstolargeenterpriseapps

Robust,productive(&fun!)Webdev

Page 12: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

AngularfollowsandehnancestheHTMLwayofdoingthingsdeclarativeinteroperable

Event-drivenModel-View-ControllerplainJSmodels

Databinding

ViewisasdecoupledaspossibilefromlogicGreatforeffectiveDesigner-Developerworkflows!

Strongpoints

Page 13: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

butIwantproof!

OK,youaregettingmeinterested

Page 14: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

OK!THISpresentationisnotPowerPointnorOpenOfficenorKeynote

Well...

Page 15: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

PressF12tobesure!

Thankshttp://plnkr.co!

It'sanAngularJSappIwroteinafewhours

Page 16: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

#

Page 17: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

AView:index.htmlastyle.css

peppered-upwithAngularJS'ng-something'directivesAmodel

data:slides.mdcode:arrayofslideobject

Acontrollerscript.js

What'sinside

Page 18: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

varslide={number:i+1,title:"Title"+i,content:"#Title\nmarkdownsample",html:"",background:"backgroundSlide"};

Themodel

Page 19: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

ngSlides.service('slidesMarkdownService',function($http){varconverter=newShowdown.converter();return{getFromMarkdown:function(path){varslides=[];

$http({method:'GET',url:path}).success(function(data,status,headers,config){varslidesToLoad=data.split(separator);//twodashesfor(i=0;i<slidesToLoad.length;i++){varslide={content:slidesToLoad[i],//..initotherslidefields};slide.html=converter.makeHtml(slide.content);slides.push(slide);}});returnslides;}}})

Aservicetoloadthemodelfrommarkdown

Page 20: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

bindingthemodeltothehtml<bodyng-app="ngSlides"ng-class="slides[currentSlide].background"ng-controller="presentationCtrl">

<divid="slidesContainer"class="slidesContainer"><divclass="slide"ng-repeat="slideinslides"ng-show="slide.number==currentSlide">

<divng-bind-html="slide.html"></div>

<h4class="number">{{slide.number}}</h4>

</div>

</div></body>

andaverysimplecssforpositioningelementsinthepage

Asimpledeclarativeview

Page 21: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

ngSlides.controller("presentationCtrl",function($scope,$http,$rootScope,slidesMarkdownService){

$scope.slides=slidesMarkdownService.getFromMarkdown('slides.md');

$scope.currentSlide=0;

$scope.next=function(){$scope.currentSlide=$scope.currentSlide+1;

};

$scope.previous=function(){$scope.currentSlide=$scope.currentSlide-1;};

});

Acontrollerfocusedoninteraction

Page 22: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

$applyutilityfunctiontonotifyangularofchangesangular.element(...).scope()

toaccesscontrollermethodsandscopeoutsideangulardocument.onkeyup=KeyPressed;

functionKeyPressed(e){varkey=(window.event)?event.keyCode:e.keyCode;

varcontrollerElement=angular.element(document.getElementById("slidesContainer"));varscope=controllerElement.scope()

scope.$apply(function(){switch(key){case39:{scope.next();break;}//...

Integrationwithnon-angularcode

Page 23: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

slides.md

#It'sanAngularJSappIwroteinafewhours<br/>##PressF12tobesure!

Slidesourcesinmarkdownformat

Page 24: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

AcustomdirectiveAfewfilters

What'sinside-details

Page 25: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Anysufficientlyadvancedtechnologyisindistinguishablefrommagic.ArthurC.Clarcke

<ling-repeat="slideinslides|filter:q">...</li>

AngularJSmagic

Page 26: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

DependencyInjectionmakesfordecoupling,testability,andenrichingofyourcodeandtags

functionSlidesCtrl($scope,SlidesService){SlidesService.loadFromMarkdown('slides.md');}

AngularJSmagicismadeof

Page 27: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Transparentnavigationandhistorywith ng-view and ng-routeDatabinding

afewlittletricks(Dirtychecking)whichwilldisappearwhenthefuture(ECMAScript6object.observe)arrives

AngularJSmagicismadeof

Page 28: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Microkernelarchitecturecore:HTMLcompiler,DependencyInjection,modulesystemeverythingelseisadirective,serviceormodule

Compositionofmodulesmodule('slides',['slides.markdown'])directives<h1ng-show='enableTitle'ng-class='titleClass'>..</h1>filtersslideinslides|filter:q|orderBy:title|limit:3...

Doyouknowofothermicrokernel-basedtechnologieswithastrongfocusoncomposition?

theytendtobestrongandlonglived:-),rightLinux,Maven,Jenkins?

Thepowerofcomposition

Page 29: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

IntegrationwithotherframeworksShowdonMarkdownconverterhttps://github.com/coreyti/showdownHighlight.jsforsyntaxhighlightingplainJSforkeyboardhandling

AngularJSisopinionatedbutitwillletyoufollowadifferentwayincaseyoureallyreallyneedit

TakeadvantageofAngularJScapabilities

Page 30: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

UnitTestingmockinghttpmocking

End-To-Endtestingscenarios

Jasmine

Testing

Page 31: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Evenangularisnotperfect...yet!Dynamicpagerendering,soSEOishard

temporarysolutionswithPhantomJSontheserversideafewcloud-basedservicespersonallythinkGoogleisworkingonfixingthat

ToolingisgoodbutcanimproveSupportforlesserbrowser

Weakpoints

Page 32: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

angularJSdocsaregreat!butbewareof<ANYng-show="{expression}">Ifyouwrite<divng-show="{divEnableFlag}">

Itwon'twork!Write<divng-show="divEnableFlag">

Lessonslearnt

Page 33: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

GettingstartedisveryeasyButtogofurtheryouneedtolearnthekeyconcepts

promisesdependencyinjectiondirectivesscopes

Lessonslearnt

Page 34: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Likeallthemagicwands,youcouldenduplikeMikeyMouseastheapprenticesorcererSogetyourtraining!

OnlineCodemotiontraining(4-5februaryand4-5march2014)http://training.codemotion.it/

Lessonslearnt

Page 35: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

AngularJSmakesforgreatmockupsinteractivityinplainHTMLviews

AngularJSchangesyourwayofworking(forthebetter!)letyoufreeofconcentratingonyourideasmakesforawayfasterdevelopmentcyclemakesforawayfasterinteractionwithcustomercycleessentialforContinuousDelivery!

Lessonslearnt

Page 36: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Onlinetutorialsandvideotrainings:http://www.yearofmoo.com/http://egghead.io

AlllinksandreferencefrommyCodemotionWorkshophttps://github.com/carlobonamico/angularjs-quickstarthttps://github.com/carlobonamico/angularjs-quickstart/blob/master/references.md

FulllabfrommyCodemotionWorkshophttps://github.com/carlobonamico/angularjs-quickstart

Tolearnmore

Page 37: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

http://www.w3.org/TR/components-intro/Youtubevideo"WebComponentsinAction"http://css-tricks.com/modular-future-web-components/

WebComponents

Page 38: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

http://www.ng-book.com/AngularJSand.NEThttp://henriquat.re

Books

Page 39: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

writingaboutAngularJSandsecurityattendMarcelloTeodoritalkonJSPowerToolsintegrateAngularJSwithmyfavouriteOpenSourceserver-sidedevplatform

http://www.manydesigns.com/en/portofinopreparingthe'AdvancedAngularJS'workshop

contactusifinterested

Mycurrentplans

Page 40: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013

Exploretheseslideshttps://github.com/carlobonamico/angularjs-future-web-development-slides

Mypresentationshttp://slideshare.net/carlo.bonamico

Followmeat@carlobonamico/@nis_srlwillpublishtheseslidesinafewdays

AttendmyCodemotiontrainingshttp://training.codemotion.it/

WritemeifyouareinterestedintheupcomingAngularJSItalyonlinecommunity

andthankstoElenaVenniforthemanyideasaboutAngularinourlastprojecttogether

Thankyou!

Page 41: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013
Page 42: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013
Page 43: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013
Page 44: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013
Page 45: AngularJS: How to code today with tomorrow tools - Codemotion Milan 2013