SlideShare uma empresa Scribd logo
1 de 56
Workingwith
Microsoft WebCamp 2014
May 20, 2014
2Aboutme
/56
André Vala
SharePoint Solutions Architect
Office & SharePoint Solutions Team Leader
andre.vala@create.pt
@atomicvee
http://blogit.create.pt/blogs/andrevala
http://www.linkedin.com/in/andrevala
3Agenda
 What is AngularJS?
 Main Concepts
 Tools
 BestPractices
 Wrappingup
/56
WhatisAngularJS?
“Angular is what HTML would have
been had it been designed for
applications.”
Miško Hevery
6WhatisAngularJS?
 SinglePageApplication(SPA)JavaScriptFramework
 Implementsclient-sideMVW pattern
 No directDOM manipulation, lesscode
 Wellorganizedand highly modular
 Focusedon testing
 Supports all majordesktopand mobilebrowsers
/56
Read More: https://plus.google.com/+AngularJS/posts/aZNVhj355G2
7History
 Createdby MiškoHevery
 Opensourcesince2009
 Supportedby Google
 Large and fast-growingcommunity
WHATISANGULARJS? /56
8SinglePageApplications
 Webapplicationscomposedof a singlepage
 Views(HTML Fragments)aredynamicallyloaded into the page
 Betteruserexperience(no reloads!)
 Calls to the serveraredone asynchronouslybehind the scenes
 Requireartificialhandling of browserhistory, navigation and
bookmarks
WHATISANGULARJS? /56
9Model-View-Whatever
 Somecallit MVC, othersMVVM...
 In the end, the namedoes not
matter. It handles separationof
concernsefectivelyseparating
presentationlogicfrombusiness
logicand presentationstate.
 Whatevermeans “whatever
worksfor you”.
WHATISANGULARJS? /56
Read More: https://plus.google.com/+AngularJS/posts/aZNVhj355G2
Model View
Whatever
10Trendingtopic
WHATISANGULARJS? /56
Source: Google Trends
11Learningcurve
WHATISANGULARJS? /56
MainConcepts
13Mainconcepts
 Templates
 Directives
 Expressions
 Data binding
 Scope
/56
 Controllers
 Modules
 Filters
 Services
 Routing
HelloWorld
DEMOMAINCONCEPTS
15Helloworldapplication
MAINCONCEPTS /56
<!doctype html>
<html ng-app>
<head>
<title>Demo 01 - Page 03</title>
<script src="libs/angular.min.js"></script>
</head>
<body>
<p>Name:<input id="textInput" type="text" ng-model="PersonName" /></p>
<p>Hello <span id="nameSpan">{{PersonName}}</span>!</p>
</body>
</html>
Directive
Directive
Expression
Template
16Templates
 HTML with additional markup
 Directives
 Expressions
 Filters
 Formcontrols
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/templates
17Directives
Markerson DOM elementsthat extendHTML vocabulary
 Attachbehaviourtothe DOMelement
 TransformtheDOM elementanditschildren
Directivescanmatch:
Elements <my-dir></my-dir>
Attributes <span my-dir="exp"></span>
Comments <!-- directive: my-dir exp -->
Classes <span class="my-dir: exp;"></span>
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/directive
18Namingformats
AngularJS HTML compilersupports multiplenamingformats
ng-bind Recommendedformat.
data-ng-bind Recommendedformattosupport HTMLvalidators.
ng_bind Legacypurposes. Avoidusingit.
ng:bind Legacypurposes. Avoidusing it.
x-ng-bind Legacypurposes. Avoidusing it.
MAINCONCEPTS/DIRECTIVES /56
Read More: https://docs.angularjs.org/guide/directive
19Built-indirectives
ngApp ngBind ngBindHtml ngBindTemplate ngBlur ngChange
ngChecked ngClass ngClassEven ngClassOdd ngClick ngCloak
ngController ngCopy ngCsp ngCut ngDblClick ngDisabled
ngFocus ngForm ngHide ngHref ngIf ngInclude ngInit
ngKeydown ngKeypress ngKeyup ngList ngModel ngModelOptions
ngMousedown ngMouseenter ngMouseleave ngMousemove
ngMouseover ngNonBindable ngOpen ngPaste ngPluralize
ngReadonly ngRepeat ngSelected ngShow ngSrc ngSrcset
ngStyle ngSubmit ngTransclude ngValue ngView
MAINCONCEPTS/DIRECTIVES /56
Read More: https://docs.angularjs.org/guide/directive
20Expressions
JavaScript-likecodesnippetsplacedinsidebindingssuchas
{{ expression }}
ValidAngularexpressions:
 {{ 1 + 2 }}
 {{ a + b }}
 {{ user.name }}
 {{ items[index] }}
Additionalnotesaboutexpressions:
 Controlflowstatementsarenotsupported(conditionals,loopsorexceptions)
 Youcanusefiltersinsideexpressionstoformatdata
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/expression
Expressions
DEMOMAINCONCEPTS
22Databinding
Automatic synchronizationof data betweenthe Modeland the View.
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/databinding
View
Template Model
One-time
merge
One-WayDataBinding
View
Template
Model
Continuous updates
Model is Single-Source-of-Truth
Compile
Changes to Model
updates View
Changes to View
updates Model
Two-WayDataBinding
Two-waydatabinding
DEMOMAINCONCEPTS
24Scope
 Objectthat refersto the applicationModel
 Valuesstored in variablesin the Scopebelong to the Model
 The glue betweenthe Controllerand the View
 Scopesarehierarchicaland followthe
DOM structureof the application
 EveryAngular applicationhas a root
scope($rootScope)mapped to the
elementlinked to ngApp directive
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/scope
25Controllers
 JavaScriptconstructorfunctions used to augmentthe Scope
 Newchild scopeis createdand
injectedas a constructor
parameter($scope)
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/controller
26Howtousecontrollers
Creatinga controllerinthe globalnamespace
function MyController($scope) {
...
}
Attachinga controllerto the DOM
<div ng-controller="MyController">
MAINCONCEPTS/CONTROLLERS /56
Read More: https://docs.angularjs.org/guide/controller
27Whentousecontrollers
 Usecontrollersto:
 Setup theinitialstateofthe$scope object
 Add behaviourtothe$scope object
 Do not use controllersto:
 ManipulateDOM(usedatabindinganddirectivesinstead)
 Formatinput (useformcontrolsinstead)
 Filteroutput (usefiltersinstead)
 Sharecodeorstateacrosscontrollers(useservicesinstead)
MAINCONCEPTS/CONTROLLERS /56
Read More: https://docs.angularjs.org/guide/controller
Usingcontrollers
DEMOMAINCONCEPTS
29Module
 Reusablecontainerfor differentfeaturesof anapp.
 Candependon othermodules.
Creatinga module
angular.module('myApp', []);
angular.module('myApp', ['myOtherModule']);
Referencinganapp’smainmodule
<html ng-app="myApp">
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/module
Usingmodules
DEMOMAINCONCEPTS
31Filters
 A filterformatsthevalueof anexpressionfor display to the user
 Can be used in view templates,controllers,servicesand directives
 You can createyour ownfilters (in a module)
 Built-in filters:
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/filter
Currency
Date
Filter
Json
LimitTo
Lowercase
Number
OrderBy
Uppercase
32Usingfiltersinviewtemplates
Singlefiltersyntax
{{ expression | filter }}
Example:{{ 12 | currency }} returns $12.00
Chainedfilterssyntax
{{ expression | filter1 | filter2 | ... }}
Filterwitharguments
{{ expression | filter:argument1:argument2... }}
Example:{{ 12 | number:2 }} returns 12.00
MAINCONCEPTS/FILTERS /56
Read More: https://docs.angularjs.org/guide/filter
33Usingfiltersincontrollers,servicesanddirectives
angular.module('FilterInControllerModule', []).
controller('FilterController', ['filterFilter', function(filterFilter) {
this.array = [
{name: 'Tobias'},
{name: 'Jeff'},
{name: 'Brian'},
{name: 'Igor'},
{name: 'James'},
{name: 'Brad'}
];
this.filteredArray = filterFilter(this.array, 'a');
}]);
MAINCONCEPTS/FILTERS /56
Read More: https://docs.angularjs.org/guide/filter
Inject filter in controller using
<filter name>Filter syntax
Receive filter function
as a parameter
Call filter with value to format
and additional parameters
34Creatingfilters
angular.module('MyFilterModule', []).
filter('myfilter', function() {
return function(input) {
...
return output;
};
});
MAINCONCEPTS/FILTERS /56
Read More: https://docs.angularjs.org/guide/filter
User the filter provider to
create a new filter in the
module
Name the filter
Return the filter function. The first
argument is the input value.
Additional arguments can be used.
Usingfilters
DEMOMAINCONCEPTS
36Services
 Reusablebusiness logiccomponentes,independentof views,wired
togetherusing dependencyinjection(DI).
 Singletonsgeneratedby a servicefactory.
 Angular only instantiatesa serviceif thereis a dependencyfor it.
 Built-in servicesstart with $.
Examples:$log, $http, $filter,$exceptionHandler
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/services
37Usingaservice
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', ['$scope', '$http', function (scope, http) {
http.get(‘countries.json').success(function(data) {
scope.countries = data;
});
}]);
MAINCONCEPTS/SERVICES /56
Inject $http service using DI
Receive service object
as a parameter
Call method on service
Read More: https://docs.angularjs.org/guide/services
38Creatingaservice
var myModule = angular.module('myModule', []);
myModule.factory('serviceId', function() {
var shinyNewServiceInstance;
//factory function body that constructs shinyNewServiceInstance
return shinyNewServiceInstance;
});
MAINCONCEPTS/SERVICES /56
Return a service instance
Register a new factory function for the service
Read More: https://docs.angularjs.org/guide/services
39Recipes
var myApp = angular.module('myApp',[]);
myApp.provider('MyFactory', function() {...});
myApp.factory('MyFactory', function() {...});
myApp.service('MyFactory', function() {...});
myApp.constant('MyConstant', 'My Constant Value');
myApp.value('MyValue', 35);
MAINCONCEPTS/SERVICES /56
Usingservices
DEMOMAINCONCEPTS
41Multipleviews
 Most applicationsarecomposedof morethan one view
 In Single PageApplicationsall viewsare renderedin the same page
(LayoutTemplate)which containsall the commonpage elements
 Eachview(PartialTemplate)is placedin its own file and dynamically
loadedinto the LayoutTemplate page
MAINCONCEPTS /56
42Multipleviews
MAINCONCEPTS /56
index.html
header.html
a1.html b2.html
a2.html
b1.html
b3.html
a3.html
Layout Template
Partial Template
Partial Template
Partial Template
Partial Template
43Routing
 Routing is providedby the ngRoute module(separatedistribution)
 Routesare declaredvia the $routeProvider fromthe $route service
 Supports deeplinking(history,bookmarksand browserback/forward
buttons)
 Partialviewsarerenderedby the ngView directive
MAINCONCEPTS /56
44Routingconfiguration
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl‘
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);
MAINCONCEPTS/ROUTING /56
Route
Dependency on
ngRoute module
Default Route
Route with variable URL. PhoneId value
will be placed in $routeParams object
Routing
DEMOMAINCONCEPTS
Bestpractices
47BestPractices
 In Views/Templates
 Usedirectivesforabstractingcommonmarkups,extensions
 Donotusecomplexexpressionsinbindings.Movethemtocontrollers.
 Optimizeuseofbindings.Lessbindings=fasterapplication.
 In Controllers
 Keepthemlight.Useservicestooffloadfunctionality.
 NoDOMmanipulations!Usedirectivesforthat.
/56
48BestPractices
 In Directives
 Preferusingdirectivesaselementsorattributesoverclassesandcomments
 Donotng-prefixforyourdirectives
 Createisolatescopestoavoidacidentaloverridesofproperties
 Createmodulesto group controllers,services,directivesand filters
/56
Tools
50Tools
 IDE: Visual Studio, NetBeans,WebStorm
 Utils: JSFiddle, BatarangPlugin for Chrome
 Static Code Analysis:JSHint
 Unit Testing: Karma
/56
Wrappingup
52Wrappingup
 AngularJS is a modular JavaScriptSPA framework
 Has a lot of great featuresbut a steeplearningcurve
 Greatfor CRUD applicationsbut not suitable for everytype of
application
 Worksvery wellwith some JavaScriptlibraries(such as jQuery)but
not so wellwith others
 Increasesdeveloperproductivity in small/medium applicationsbut
can be quite heavyfor complexapplications
/56
53Nexttime...
 Custom directives
 Formcontrolsand validation
 Unit testing
 End-to-endtesting
 Animations
WRAPPINGUP /56
54Resources
Officialdocumentation
 Projecthomepage:https://angularjs.org/
 DeveloperGuide:https://docs.angularjs.org/guide
 Tutorial:https://docs.angularjs.org/tutorial
 APIReference:https://docs.angularjs.org/api
 BuiltwithAngular:https://builtwith.angularjs.org
Trainingvideosandtutorialsfordevelopers
 Egghead:https://egghead.io/technologies/angularjs
Additionalstuff
 Angularmodules:http://ngmodules.org/
WRAPPINGUP /56
ThankYou!
Downloadslidedeck:http://1drv.ms/1h1YOlS
Downloaddemos:http://1drv.ms/1h1YJyP
Working with AngularJS

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Angular js
Angular jsAngular js
Angular js
 
Techlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with VaadinTechlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with Vaadin
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까
 
AngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue SolutionsAngularJS Project Setup step-by- step guide - RapidValue Solutions
AngularJS Project Setup step-by- step guide - RapidValue Solutions
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadin
 
Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular U
 
Android DevConference - Android Clean Architecture
Android DevConference - Android Clean ArchitectureAndroid DevConference - Android Clean Architecture
Android DevConference - Android Clean Architecture
 
Different way to share data between controllers in angular js
Different way to share data between controllers in angular jsDifferent way to share data between controllers in angular js
Different way to share data between controllers in angular js
 
Angular Mini Hackathon Code Talks 2019
Angular Mini Hackathon Code Talks 2019Angular Mini Hackathon Code Talks 2019
Angular Mini Hackathon Code Talks 2019
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 
React django
React djangoReact django
React django
 
Modern android development
Modern android developmentModern android development
Modern android development
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
Vaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIVaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UI
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google Guice
 
Vaadin Components
Vaadin ComponentsVaadin Components
Vaadin Components
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Exploring CameraX from JetPack
Exploring CameraX from JetPackExploring CameraX from JetPack
Exploring CameraX from JetPack
 

Semelhante a Working with AngularJS

Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
Oro Inc.
 

Semelhante a Working with AngularJS (20)

20141002 delapsley-socalangularjs-final
20141002 delapsley-socalangularjs-final20141002 delapsley-socalangularjs-final
20141002 delapsley-socalangularjs-final
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
Angular JS deep dive
Angular JS deep diveAngular JS deep dive
Angular JS deep dive
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Struts 1
Struts 1Struts 1
Struts 1
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
The Google App Engine Oil Framework
The Google App Engine Oil FrameworkThe Google App Engine Oil Framework
The Google App Engine Oil Framework
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
WJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJSWJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJS
 

Mais de André Vala

Mais de André Vala (20)

RGPD - Testemunho do Mundo Real
RGPD - Testemunho do Mundo RealRGPD - Testemunho do Mundo Real
RGPD - Testemunho do Mundo Real
 
Office Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft TeamsOffice Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft Teams
 
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
 
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint WebhooksFrom Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks
 
Planning the Death Star with Microsoft Planner
Planning the Death Star with Microsoft PlannerPlanning the Death Star with Microsoft Planner
Planning the Death Star with Microsoft Planner
 
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint WebhooksFrom Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks
 
Microsoft Planner Deep Dive
Microsoft Planner Deep DiveMicrosoft Planner Deep Dive
Microsoft Planner Deep Dive
 
SharePoint - Presente e Futuro
SharePoint - Presente e FuturoSharePoint - Presente e Futuro
SharePoint - Presente e Futuro
 
Office 365 Groups Deep Dive
Office 365 Groups Deep DiveOffice 365 Groups Deep Dive
Office 365 Groups Deep Dive
 
Soluções com Office Graph
Soluções com Office GraphSoluções com Office Graph
Soluções com Office Graph
 
Host-Named Site Collections in SharePoint 2013
Host-Named Site Collections in SharePoint 2013Host-Named Site Collections in SharePoint 2013
Host-Named Site Collections in SharePoint 2013
 
User License Enforcement em SharePoint 2013
User License Enforcement em SharePoint 2013User License Enforcement em SharePoint 2013
User License Enforcement em SharePoint 2013
 
How To Use Host-Named Site Collections
How To Use Host-Named Site CollectionsHow To Use Host-Named Site Collections
How To Use Host-Named Site Collections
 
Novidades na pesquisa no SharePoint 2013
Novidades na pesquisa no SharePoint 2013Novidades na pesquisa no SharePoint 2013
Novidades na pesquisa no SharePoint 2013
 
Building Public Web Sites in SharePoint 2010
Building Public Web Sites in SharePoint 2010 Building Public Web Sites in SharePoint 2010
Building Public Web Sites in SharePoint 2010
 
SharePoint + Azure = Better Together
SharePoint + Azure = Better TogetherSharePoint + Azure = Better Together
SharePoint + Azure = Better Together
 
Federated Authentication in SharePoint 2010
Federated Authentication in SharePoint 2010Federated Authentication in SharePoint 2010
Federated Authentication in SharePoint 2010
 
Using BCS to integrate Azure Services with SharePoint 2010
Using BCS to integrate Azure Services with SharePoint 2010Using BCS to integrate Azure Services with SharePoint 2010
Using BCS to integrate Azure Services with SharePoint 2010
 
LINQ to SharePoint
LINQ to SharePointLINQ to SharePoint
LINQ to SharePoint
 
Solução de Negócio baseadas em Office 2010 e SharePoint 2010
Solução de Negócio baseadas em Office 2010 e SharePoint 2010Solução de Negócio baseadas em Office 2010 e SharePoint 2010
Solução de Negócio baseadas em Office 2010 e SharePoint 2010
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Working with AngularJS

  • 2. 2Aboutme /56 André Vala SharePoint Solutions Architect Office & SharePoint Solutions Team Leader andre.vala@create.pt @atomicvee http://blogit.create.pt/blogs/andrevala http://www.linkedin.com/in/andrevala
  • 3. 3Agenda  What is AngularJS?  Main Concepts  Tools  BestPractices  Wrappingup /56
  • 5. “Angular is what HTML would have been had it been designed for applications.” Miško Hevery
  • 6. 6WhatisAngularJS?  SinglePageApplication(SPA)JavaScriptFramework  Implementsclient-sideMVW pattern  No directDOM manipulation, lesscode  Wellorganizedand highly modular  Focusedon testing  Supports all majordesktopand mobilebrowsers /56 Read More: https://plus.google.com/+AngularJS/posts/aZNVhj355G2
  • 7. 7History  Createdby MiškoHevery  Opensourcesince2009  Supportedby Google  Large and fast-growingcommunity WHATISANGULARJS? /56
  • 8. 8SinglePageApplications  Webapplicationscomposedof a singlepage  Views(HTML Fragments)aredynamicallyloaded into the page  Betteruserexperience(no reloads!)  Calls to the serveraredone asynchronouslybehind the scenes  Requireartificialhandling of browserhistory, navigation and bookmarks WHATISANGULARJS? /56
  • 9. 9Model-View-Whatever  Somecallit MVC, othersMVVM...  In the end, the namedoes not matter. It handles separationof concernsefectivelyseparating presentationlogicfrombusiness logicand presentationstate.  Whatevermeans “whatever worksfor you”. WHATISANGULARJS? /56 Read More: https://plus.google.com/+AngularJS/posts/aZNVhj355G2 Model View Whatever
  • 13. 13Mainconcepts  Templates  Directives  Expressions  Data binding  Scope /56  Controllers  Modules  Filters  Services  Routing
  • 15. 15Helloworldapplication MAINCONCEPTS /56 <!doctype html> <html ng-app> <head> <title>Demo 01 - Page 03</title> <script src="libs/angular.min.js"></script> </head> <body> <p>Name:<input id="textInput" type="text" ng-model="PersonName" /></p> <p>Hello <span id="nameSpan">{{PersonName}}</span>!</p> </body> </html> Directive Directive Expression Template
  • 16. 16Templates  HTML with additional markup  Directives  Expressions  Filters  Formcontrols MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/templates
  • 17. 17Directives Markerson DOM elementsthat extendHTML vocabulary  Attachbehaviourtothe DOMelement  TransformtheDOM elementanditschildren Directivescanmatch: Elements <my-dir></my-dir> Attributes <span my-dir="exp"></span> Comments <!-- directive: my-dir exp --> Classes <span class="my-dir: exp;"></span> MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/directive
  • 18. 18Namingformats AngularJS HTML compilersupports multiplenamingformats ng-bind Recommendedformat. data-ng-bind Recommendedformattosupport HTMLvalidators. ng_bind Legacypurposes. Avoidusingit. ng:bind Legacypurposes. Avoidusing it. x-ng-bind Legacypurposes. Avoidusing it. MAINCONCEPTS/DIRECTIVES /56 Read More: https://docs.angularjs.org/guide/directive
  • 19. 19Built-indirectives ngApp ngBind ngBindHtml ngBindTemplate ngBlur ngChange ngChecked ngClass ngClassEven ngClassOdd ngClick ngCloak ngController ngCopy ngCsp ngCut ngDblClick ngDisabled ngFocus ngForm ngHide ngHref ngIf ngInclude ngInit ngKeydown ngKeypress ngKeyup ngList ngModel ngModelOptions ngMousedown ngMouseenter ngMouseleave ngMousemove ngMouseover ngNonBindable ngOpen ngPaste ngPluralize ngReadonly ngRepeat ngSelected ngShow ngSrc ngSrcset ngStyle ngSubmit ngTransclude ngValue ngView MAINCONCEPTS/DIRECTIVES /56 Read More: https://docs.angularjs.org/guide/directive
  • 20. 20Expressions JavaScript-likecodesnippetsplacedinsidebindingssuchas {{ expression }} ValidAngularexpressions:  {{ 1 + 2 }}  {{ a + b }}  {{ user.name }}  {{ items[index] }} Additionalnotesaboutexpressions:  Controlflowstatementsarenotsupported(conditionals,loopsorexceptions)  Youcanusefiltersinsideexpressionstoformatdata MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/expression
  • 22. 22Databinding Automatic synchronizationof data betweenthe Modeland the View. MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/databinding View Template Model One-time merge One-WayDataBinding View Template Model Continuous updates Model is Single-Source-of-Truth Compile Changes to Model updates View Changes to View updates Model Two-WayDataBinding
  • 24. 24Scope  Objectthat refersto the applicationModel  Valuesstored in variablesin the Scopebelong to the Model  The glue betweenthe Controllerand the View  Scopesarehierarchicaland followthe DOM structureof the application  EveryAngular applicationhas a root scope($rootScope)mapped to the elementlinked to ngApp directive MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/scope
  • 25. 25Controllers  JavaScriptconstructorfunctions used to augmentthe Scope  Newchild scopeis createdand injectedas a constructor parameter($scope) MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/controller
  • 26. 26Howtousecontrollers Creatinga controllerinthe globalnamespace function MyController($scope) { ... } Attachinga controllerto the DOM <div ng-controller="MyController"> MAINCONCEPTS/CONTROLLERS /56 Read More: https://docs.angularjs.org/guide/controller
  • 27. 27Whentousecontrollers  Usecontrollersto:  Setup theinitialstateofthe$scope object  Add behaviourtothe$scope object  Do not use controllersto:  ManipulateDOM(usedatabindinganddirectivesinstead)  Formatinput (useformcontrolsinstead)  Filteroutput (usefiltersinstead)  Sharecodeorstateacrosscontrollers(useservicesinstead) MAINCONCEPTS/CONTROLLERS /56 Read More: https://docs.angularjs.org/guide/controller
  • 29. 29Module  Reusablecontainerfor differentfeaturesof anapp.  Candependon othermodules. Creatinga module angular.module('myApp', []); angular.module('myApp', ['myOtherModule']); Referencinganapp’smainmodule <html ng-app="myApp"> MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/module
  • 31. 31Filters  A filterformatsthevalueof anexpressionfor display to the user  Can be used in view templates,controllers,servicesand directives  You can createyour ownfilters (in a module)  Built-in filters: MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/filter Currency Date Filter Json LimitTo Lowercase Number OrderBy Uppercase
  • 32. 32Usingfiltersinviewtemplates Singlefiltersyntax {{ expression | filter }} Example:{{ 12 | currency }} returns $12.00 Chainedfilterssyntax {{ expression | filter1 | filter2 | ... }} Filterwitharguments {{ expression | filter:argument1:argument2... }} Example:{{ 12 | number:2 }} returns 12.00 MAINCONCEPTS/FILTERS /56 Read More: https://docs.angularjs.org/guide/filter
  • 33. 33Usingfiltersincontrollers,servicesanddirectives angular.module('FilterInControllerModule', []). controller('FilterController', ['filterFilter', function(filterFilter) { this.array = [ {name: 'Tobias'}, {name: 'Jeff'}, {name: 'Brian'}, {name: 'Igor'}, {name: 'James'}, {name: 'Brad'} ]; this.filteredArray = filterFilter(this.array, 'a'); }]); MAINCONCEPTS/FILTERS /56 Read More: https://docs.angularjs.org/guide/filter Inject filter in controller using <filter name>Filter syntax Receive filter function as a parameter Call filter with value to format and additional parameters
  • 34. 34Creatingfilters angular.module('MyFilterModule', []). filter('myfilter', function() { return function(input) { ... return output; }; }); MAINCONCEPTS/FILTERS /56 Read More: https://docs.angularjs.org/guide/filter User the filter provider to create a new filter in the module Name the filter Return the filter function. The first argument is the input value. Additional arguments can be used.
  • 36. 36Services  Reusablebusiness logiccomponentes,independentof views,wired togetherusing dependencyinjection(DI).  Singletonsgeneratedby a servicefactory.  Angular only instantiatesa serviceif thereis a dependencyfor it.  Built-in servicesstart with $. Examples:$log, $http, $filter,$exceptionHandler MAINCONCEPTS /56 Read More: https://docs.angularjs.org/guide/services
  • 37. 37Usingaservice var countryApp = angular.module('countryApp', []); countryApp.controller('CountryCtrl', ['$scope', '$http', function (scope, http) { http.get(‘countries.json').success(function(data) { scope.countries = data; }); }]); MAINCONCEPTS/SERVICES /56 Inject $http service using DI Receive service object as a parameter Call method on service Read More: https://docs.angularjs.org/guide/services
  • 38. 38Creatingaservice var myModule = angular.module('myModule', []); myModule.factory('serviceId', function() { var shinyNewServiceInstance; //factory function body that constructs shinyNewServiceInstance return shinyNewServiceInstance; }); MAINCONCEPTS/SERVICES /56 Return a service instance Register a new factory function for the service Read More: https://docs.angularjs.org/guide/services
  • 39. 39Recipes var myApp = angular.module('myApp',[]); myApp.provider('MyFactory', function() {...}); myApp.factory('MyFactory', function() {...}); myApp.service('MyFactory', function() {...}); myApp.constant('MyConstant', 'My Constant Value'); myApp.value('MyValue', 35); MAINCONCEPTS/SERVICES /56
  • 41. 41Multipleviews  Most applicationsarecomposedof morethan one view  In Single PageApplicationsall viewsare renderedin the same page (LayoutTemplate)which containsall the commonpage elements  Eachview(PartialTemplate)is placedin its own file and dynamically loadedinto the LayoutTemplate page MAINCONCEPTS /56
  • 42. 42Multipleviews MAINCONCEPTS /56 index.html header.html a1.html b2.html a2.html b1.html b3.html a3.html Layout Template Partial Template Partial Template Partial Template Partial Template
  • 43. 43Routing  Routing is providedby the ngRoute module(separatedistribution)  Routesare declaredvia the $routeProvider fromthe $route service  Supports deeplinking(history,bookmarksand browserback/forward buttons)  Partialviewsarerenderedby the ngView directive MAINCONCEPTS /56
  • 44. 44Routingconfiguration var myApp = angular.module('myApp',['ngRoute']); myApp.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', { templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl‘ }). when('/phones/:phoneId', { templateUrl: 'partials/phone-detail.html', controller: 'PhoneDetailCtrl' }). otherwise({ redirectTo: '/phones' }); }]); MAINCONCEPTS/ROUTING /56 Route Dependency on ngRoute module Default Route Route with variable URL. PhoneId value will be placed in $routeParams object
  • 47. 47BestPractices  In Views/Templates  Usedirectivesforabstractingcommonmarkups,extensions  Donotusecomplexexpressionsinbindings.Movethemtocontrollers.  Optimizeuseofbindings.Lessbindings=fasterapplication.  In Controllers  Keepthemlight.Useservicestooffloadfunctionality.  NoDOMmanipulations!Usedirectivesforthat. /56
  • 48. 48BestPractices  In Directives  Preferusingdirectivesaselementsorattributesoverclassesandcomments  Donotng-prefixforyourdirectives  Createisolatescopestoavoidacidentaloverridesofproperties  Createmodulesto group controllers,services,directivesand filters /56
  • 49. Tools
  • 50. 50Tools  IDE: Visual Studio, NetBeans,WebStorm  Utils: JSFiddle, BatarangPlugin for Chrome  Static Code Analysis:JSHint  Unit Testing: Karma /56
  • 52. 52Wrappingup  AngularJS is a modular JavaScriptSPA framework  Has a lot of great featuresbut a steeplearningcurve  Greatfor CRUD applicationsbut not suitable for everytype of application  Worksvery wellwith some JavaScriptlibraries(such as jQuery)but not so wellwith others  Increasesdeveloperproductivity in small/medium applicationsbut can be quite heavyfor complexapplications /56
  • 53. 53Nexttime...  Custom directives  Formcontrolsand validation  Unit testing  End-to-endtesting  Animations WRAPPINGUP /56
  • 54. 54Resources Officialdocumentation  Projecthomepage:https://angularjs.org/  DeveloperGuide:https://docs.angularjs.org/guide  Tutorial:https://docs.angularjs.org/tutorial  APIReference:https://docs.angularjs.org/api  BuiltwithAngular:https://builtwith.angularjs.org Trainingvideosandtutorialsfordevelopers  Egghead:https://egghead.io/technologies/angularjs Additionalstuff  Angularmodules:http://ngmodules.org/ WRAPPINGUP /56