angularjs: how to code today with tomorrow tools

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

Upload: codemotion

Post on 18-Dec-2014

1.717 views

Category:

Technology


0 download

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

TRANSCRIPT

Page 1: AngularJS: How to code today with tomorrow tools

AngularJS

HowtocodetodaywithtomorrowtoolsCarloBonamico-@carlobonamico

[email protected]@nispro.it

WebFramework

Page 2: AngularJS: How to code today with tomorrow tools

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

toimplementmynextgreatservice/project...afewmonthsgoby...

WTF!!Ididnotthinkwebdevelopmentwascouldbethatmessy!SpaghetticodetastesbetterinadynamiclanguagesuchasJSIspentmostofmytimejugglingtheDOMIcannotintegratetheFormwidgetsIlovewiththechartslibraryIloveWhereismodularization?andencapsulation?

"everything"canfiddlewith"everything"...

OK,woIwillgoforHTML5

Page 4: AngularJS: How to code today with tomorrow tools

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

debugginggetsharderrefactoringgetshardereffectivetestinggetsimpossible

Whentheteamgrows,collaborationbecomesharder!everytimeadesignermakesabeautifullook,wespenddaysimplementingitandregressiontesting

It'sbecomingimpossibletoevolve!

Thentheproblemsbegin

Page 5: AngularJS: How to code today with tomorrow tools

Please,beforeIgobacktoDesktopdevelopment,canyoutellmeifthereisabetterway?

HELPME!

Page 6: AngularJS: How to code today with tomorrow tools

Almostanobrainer:goforAdobeFlex!Ithas

encapsulation,interfaceseventdrivenGUImodularandreusablecomoponentsgreattooling

Thewebplatformwasjustnotthereyet...

IfIweretoanswerthisquestionin2008...

Page 7: AngularJS: How to code today with tomorrow tools

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

Blurrysituation...

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

Butplease,IHAVEtodeliveragreatWebAppinafewmonths!

Andnow?onendof2013

Page 9: AngularJS: How to code today with tomorrow tools

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

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

OpenSourcetoolsetbackedbyGoogle

great,activeandopencommunity

usedfromstartupstoMicrosoft,Oracle&Googleitself

Extremelyproductive,robust,testable,andscalablefrommockupstosmallappstolargeenterpriseapps

Robust,productive(&fun!)Webdev

Page 12: AngularJS: How to code today with tomorrow tools

AngularfollowsandehnancestheHTMLwayofdoingthingsdeclarativeinteroperable

Event-drivenModel-View-ControllerplainJSmodels

Databinding

ViewisasdecoupledaspossibilefromlogicGreatforeffectiveDesigner-Developerworkflows!

Strongpoints

Page 13: AngularJS: How to code today with tomorrow tools

butIwantproof!

OK,youaregettingmeinterested

Page 14: AngularJS: How to code today with tomorrow tools

OK!THISpresentationisnotPowerPointnorOpenOfficenorKeynote

Well...

Page 15: AngularJS: How to code today with tomorrow tools

PressF12tobesure!

Thankshttp://plnkr.co!

It'sanAngularJSappIwroteinafewhours

Page 16: AngularJS: How to code today with tomorrow tools

#

Page 17: AngularJS: How to code today with tomorrow tools

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

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

Themodel

Page 19: AngularJS: How to code today with tomorrow tools

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

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

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

$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

slides.md

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

Slidesourcesinmarkdownformat

Page 24: AngularJS: How to code today with tomorrow tools

AcustomdirectiveAfewfilters

What'sinside-details

Page 25: AngularJS: How to code today with tomorrow tools

Anysufficientlyadvancedtechnologyisindistinguishablefrommagic.ArthurC.Clarcke

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

AngularJSmagic

Page 26: AngularJS: How to code today with tomorrow tools

DependencyInjectionmakesfordecoupling,testability,andenrichingofyourcodeandtags

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

AngularJSmagicismadeof

Page 27: AngularJS: How to code today with tomorrow tools

Transparentnavigationandhistorywith ng-view and ng-routeDatabinding

afewlittletricks(Dirtychecking)whichwilldisappearwhenthefuture(ECMAScript6object.observe)arrives

AngularJSmagicismadeof

Page 28: AngularJS: How to code today with tomorrow tools

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

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

AngularJSisopinionatedbutitwillletyoufollowadifferentwayincaseyoureallyreallyneedit

TakeadvantageofAngularJScapabilities

Page 30: AngularJS: How to code today with tomorrow tools

UnitTestingmockinghttpmocking

End-To-Endtestingscenarios

Jasmine

Testing

Page 31: AngularJS: How to code today with tomorrow tools

Evenangularisnotperfect...yet!Dynamicpagerendering,soSEOishard

temporarysolutionswithPhantomJSontheserversideafewcloud-basedservicespersonallythinkGoogleisworkingonfixingthat

ToolingisgoodbutcanimproveSupportforlesserbrowser

Weakpoints

Page 32: AngularJS: How to code today with tomorrow tools

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

GettingstartedisveryeasyButtogofurtheryouneedtolearnthekeyconcepts

promisesdependencyinjectiondirectivesscopes

Lessonslearnt

Page 34: AngularJS: How to code today with tomorrow tools

Likeallthemagicwands,youcouldenduplikeMikeyMouseastheapprenticesorcererSogetyourtraining!

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

Lessonslearnt

Page 35: AngularJS: How to code today with tomorrow tools

AngularJSmakesforgreatmockupsinteractivityinplainHTMLviews

AngularJSchangesyourwayofworking(forthebetter!)letyoufreeofconcentratingonyourideasmakesforawayfasterdevelopmentcyclemakesforawayfasterinteractionwithcustomercycleessentialforContinuousDelivery!

Lessonslearnt

Page 36: AngularJS: How to code today with tomorrow tools

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

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

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

Books

Page 39: AngularJS: How to code today with tomorrow tools

writingaboutAngularJSandsecurityattendMarcelloTeodoritalkonJSPowerToolsintegrateAngularJSwithmyfavouriteOpenSourceserver-sidedevplatform

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

contactusifinterested

Mycurrentplans

Page 40: AngularJS: How to code today with tomorrow tools

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
Page 42: AngularJS: How to code today with tomorrow tools
Page 43: AngularJS: How to code today with tomorrow tools
Page 44: AngularJS: How to code today with tomorrow tools
Page 45: AngularJS: How to code today with tomorrow tools