SlideShare une entreprise Scribd logo
1  sur  38
AngularJS & SPA
Lorenzo Dematte'
For 33Dev @ Muse
A) server-side generator, “forms” like (aspx, Jsp/Jsf)
B) server-side templating (Haml, Mustache, Smarty)
C) server-side MVC frameworks
D) jQuery
E) Another Javascript framework
A= ?? B = ?? C = ?? D = ?? E = ??
What are you using to build web applications?
(the only image in this slide set.
Now we can move on..)
What is AngularJS?
A complete framework for rich SPA applications
What is a SPA?
●
Single Page Application
●
Client side (with server-side help)
●
Rich, responsive, fast
●
Desktop-like experience
●
“Like the big ones” (Twitter, FB, Gmail)
SPA technically
●
HTML5 + JS
●
Service
●
More likely:
– An MVC/MVVM client framework
– Lightweight REST/Json service(s)
●
Even Json non-relational DBs!
DOM Manipulation
●
It' central
●
But... Angular hides it!
AngularJS vs. jQuery
●
Don't design your page, and then change it with
DOM manipulations
●
The view is the "official record"
●
→ Data binding
– The “Angular” way
<!DOCTYPE html>
<html data-ng-app="myapp">
<head>
<title>Foo Car rental</title>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="scripts/angular.min.js"></script>
<script src="scripts/myapp.js"></script>
<body>
...
Name: <input type=”text” ng-model=”name” /> {{ name }}
1: Directives and data-binding
Demo one
More directives: ng-repeat,
expression, filters
<div ng-init="friends = [
{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'},
{name:'Johanna', age:28, gender:'girl'},
{name:'Joy', age:15, gender:'girl'},
{name:'Mary', age:28, gender:'girl'},
{name:'Peter', age:95, gender:'boy'},
{name:'Sebastian', age:50, gender:'boy'},
{name:'Erika', age:27, gender:'girl'},
{name:'Patrick', age:40, gender:'boy'},
{name:'Samantha', age:60, gender:'girl'}
]">
I have {{friends.length}} friends. They are:
<input type="search" ng-model="q" placeholder="filter friends..." />
<ul class="example-animate-container">
<li class="animate-repeat" ng-repeat="friend in friends | filter:q">
[{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
</li>
</ul>
</div>
Demo two
Filters
<div>{{ 12345.67 | currency }}</div>
<div>{{ 1288323623006 | date:"mediumDate" }}</div>
<ul ng-repeat="r in result.results | orderBy:sortBy">
<ul ng-repeat="r in result.results | filter:searchTerm | limitTo:10” >
(custom filters)
app.filter("orru", function(){
return function(text, length){
return text; // Do nothing
}
});
Demo three
2: Views, Controller, Scope
View Data
2: Views, Controller, Scope
View Data
Html Javascript objects/
JSON/something remote
2: Views, Controller, Scope
View Data
Html Javascript objects/
JSON/something remote
2: Views, Controller, Scope
View
Data
(Model)
ViewModel
(bi-directional)
binding
2: Views, Controller, Scope
View
Data
(Model)
Controller
Update
(query)
Input
(select)
2: Views, Controller, Scope
View
Data
(Model)
$scope
(bi-directional)
binding
Controller
Controllers
<!DOCTYPE html>
<html data-ng-app="myapp">
<head>
<title>Foo Car rental</title>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="scripts/angular.min.js"></script>
<script src="scripts/myapp.js"></script>
<body>
<div class="container-narrow">
<div data-ng-controller="SomeController">
<div class="masthead" data-ng-show="showNavigation()">
...
Name: <input type=”text” ng-model=”name” /> {{ name }}
Controllers
var myApp = angular.module("myApp", []);
myApp.controller('SomeController', function ($scope, someService) {
$scope.name = “Pippo”;
$scope.showNavigation = function() {
if (pathUnder("/login") || pathUnder("/registration"))
return false;
else
return true;
};
});
Demo four
3: Modules, routes,
factories/services
Modules and dependency injection
var myApp = angular.module("myApp", []);
myApp.controller('SomeController', function ($scope, someService) {
$scope.name = “Pippo”;
$scope.showNavigation = function() {
if (pathUnder("/login") || pathUnder("/registration"))
return false;
else
return true;
};
});
???
Routes
App.config(function ($routeProvider) {
$routeProvider.
when('/', {
controller: 'HomeController',
templateUrl: 'partials/home.html'
}).
when('/user-info', {
controller: 'UserController',
templateUrl: 'partials/user-info.html'
}).
when('/login', {
controller: 'LoginController',
templateUrl: 'partials/login.html'
}).
when('/registration', {
controller: 'LoginController',
templateUrl: 'partials/registration.html'
}).
when('/invalid-server-response', {
controller: 'UserController',
templateUrl: 'partials/invalid-server-response.html'
}).
when('/error', {
controller: 'UserController',
templateUrl: 'partials/error.html'
}).
otherwise({ redirectTo: '/' });
});
Routes and views
<div data-ng-view=""></div>
“Partials”
Services
angular.module("MiniResources", [], ["$provide", function($provide) {
$provide.value("miniResources", {
nameRequired : "E' necessario specificare un nome",
fieldAdded: "Campo aggiunto con successo",
emptyField: "<vuoto>",
startFlowQuestion: "Sei sicuro di voler cominicare un flusso",
startFlow: "Comincia un nuovo flusso",
yes: "Si",
no: "No",
back: "Torna indietro",
all: "Tutti",
processing: "Sto elaborando",
error: "Errore",
close: "Chiudi"
});
}]);
Service usage
●
They are injected!
miniApp.controller("StepController", function ($scope, …, miniResources)
Demo five
4: Custom directives
app.directive('ngContent', function ($parse) {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs) {
if (attrs.ngModel && element.text()) {
$parse(attrs.ngModel).assign(scope, element.text());
}
scope.$watch(attrs.ngModel, function(value) {
element.text(value);
});
}
};
});
Where?
require: '^parentDirective' will give you access to the parentDirective
^ -- Look for the controller on parent elements, not just on the local scope
? -- Don't raise an error if the controller isn't found
Demo six
5: UI
UI elements in Angular
<h4>Static arrays</h4>
<pre>Model: {{selected | json}}</pre>
<input type="text" ng-model="selected"
typeahead="state for state in states | filter:$viewValue | limitTo:8"
class="form-control">
<h4>Asynchronous results</h4>
<pre>Model: {{asyncSelected | json}}</pre>
<input type="text" ng-model="asyncSelected"
placeholder="Locations loaded via $http"
typeahead="address for address in getLocation($viewValue) |
filter:$viewValue"
typeahead-loading="loadingLocations" class="form-control">
Demo seven
...but... in the real world?
●
#1: Javascript vs. “Security through obscurity”
(F12 - but it is actually good because...)
●
#2: you have to design a SPA keeping #1 in
mind
●
#3: SPA are almost never “single page”
●
#4: HTTPS and/or OAuth!
In the real world...
●
You almost always “blur” the lines
– Server-side generation AND client-side rendering
– Multiple pages for multiple roles
– Use your server!
Thank you!

Contenu connexe

Tendances

Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRJavier Abadía
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)jeresig
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.jsjeresig
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS OverviewEyal Vardi
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDartLoc Nguyen
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoJavier Abadía
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 

Tendances (20)

Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
jQuery
jQueryjQuery
jQuery
 
AngularJs
AngularJsAngularJs
AngularJs
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Web components
Web componentsWeb components
Web components
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
HTML,CSS Next
HTML,CSS NextHTML,CSS Next
HTML,CSS Next
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery
jQueryjQuery
jQuery
 
Django + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar DjangoDjango + Vue, JavaScript de 3ª generación para modernizar Django
Django + Vue, JavaScript de 3ª generación para modernizar Django
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 

En vedette

DBA Basics guide
DBA Basics guideDBA Basics guide
DBA Basics guideazoznasser1
 
Sistem keamanan komputer
Sistem keamanan komputerSistem keamanan komputer
Sistem keamanan komputerRhusman 05
 
Curso richfaces 3.3.3 II
Curso richfaces 3.3.3 IICurso richfaces 3.3.3 II
Curso richfaces 3.3.3 IIeclaudioaugusto
 
Especial Linux Magazine Software Público
Especial Linux Magazine Software PúblicoEspecial Linux Magazine Software Público
Especial Linux Magazine Software PúblicoGovBR
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2Ben Abdallah Helmi
 
Anonos U.S. Patent Number 9,087,215
Anonos U.S. Patent Number 9,087,215Anonos U.S. Patent Number 9,087,215
Anonos U.S. Patent Number 9,087,215Ted Myerson
 
Montando seu DataCenter Pessoal - Fernando Massen
Montando seu DataCenter Pessoal - Fernando MassenMontando seu DataCenter Pessoal - Fernando Massen
Montando seu DataCenter Pessoal - Fernando MassenTchelinux
 
Os 10 Maus Hábitos dos Desenvolvedores JSF
Os 10 Maus Hábitos dos Desenvolvedores JSFOs 10 Maus Hábitos dos Desenvolvedores JSF
Os 10 Maus Hábitos dos Desenvolvedores JSFtarsobessa
 
What's Next with Government Big Data
What's Next with Government Big Data What's Next with Government Big Data
What's Next with Government Big Data GovLoop
 
Rails On Spring
Rails On SpringRails On Spring
Rails On Springswamy g
 
Alumni Engagement: Gettting Them to Comeback
Alumni Engagement: Gettting Them to ComebackAlumni Engagement: Gettting Them to Comeback
Alumni Engagement: Gettting Them to ComebackAgilon LLC
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3Ben Abdallah Helmi
 
Caderno SISP 2012
Caderno SISP 2012Caderno SISP 2012
Caderno SISP 2012GovBR
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five yearsJacob Kaplan-Moss
 

En vedette (20)

Free content creation in postindustrial sociality
Free content creation in postindustrial socialityFree content creation in postindustrial sociality
Free content creation in postindustrial sociality
 
DBA Basics guide
DBA Basics guideDBA Basics guide
DBA Basics guide
 
MTBiz February 2014
MTBiz February 2014MTBiz February 2014
MTBiz February 2014
 
Sistem keamanan komputer
Sistem keamanan komputerSistem keamanan komputer
Sistem keamanan komputer
 
Curso richfaces 3.3.3 II
Curso richfaces 3.3.3 IICurso richfaces 3.3.3 II
Curso richfaces 3.3.3 II
 
Especial Linux Magazine Software Público
Especial Linux Magazine Software PúblicoEspecial Linux Magazine Software Público
Especial Linux Magazine Software Público
 
Db2 howto-linux
Db2 howto-linuxDb2 howto-linux
Db2 howto-linux
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2
 
Anonos U.S. Patent Number 9,087,215
Anonos U.S. Patent Number 9,087,215Anonos U.S. Patent Number 9,087,215
Anonos U.S. Patent Number 9,087,215
 
Planet talent
Planet talentPlanet talent
Planet talent
 
S5L2010 datasheet
S5L2010 datasheetS5L2010 datasheet
S5L2010 datasheet
 
Montando seu DataCenter Pessoal - Fernando Massen
Montando seu DataCenter Pessoal - Fernando MassenMontando seu DataCenter Pessoal - Fernando Massen
Montando seu DataCenter Pessoal - Fernando Massen
 
FinistJUG - Apache TomEE
FinistJUG - Apache TomEEFinistJUG - Apache TomEE
FinistJUG - Apache TomEE
 
Os 10 Maus Hábitos dos Desenvolvedores JSF
Os 10 Maus Hábitos dos Desenvolvedores JSFOs 10 Maus Hábitos dos Desenvolvedores JSF
Os 10 Maus Hábitos dos Desenvolvedores JSF
 
What's Next with Government Big Data
What's Next with Government Big Data What's Next with Government Big Data
What's Next with Government Big Data
 
Rails On Spring
Rails On SpringRails On Spring
Rails On Spring
 
Alumni Engagement: Gettting Them to Comeback
Alumni Engagement: Gettting Them to ComebackAlumni Engagement: Gettting Them to Comeback
Alumni Engagement: Gettting Them to Comeback
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3
 
Caderno SISP 2012
Caderno SISP 2012Caderno SISP 2012
Caderno SISP 2012
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five years
 

Similaire à AngularJS and SPA

Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSbuttyx
 
Spine js & creating non blocking user interfaces
Spine js & creating non blocking user interfacesSpine js & creating non blocking user interfaces
Spine js & creating non blocking user interfacesHjörtur Hilmarsson
 
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 AngularJSmurtazahaveliwala
 
Angular.js is super cool
Angular.js is super coolAngular.js is super cool
Angular.js is super coolMaksym Hopei
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Enginethomas alisi
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
Angular JS deep dive
Angular JS deep diveAngular JS deep dive
Angular JS deep diveAxilis
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularErik Guzman
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java DevelopersLoc Nguyen
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014Dariusz Kalbarczyk
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 

Similaire à AngularJS and SPA (20)

Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Spine js & creating non blocking user interfaces
Spine js & creating non blocking user interfacesSpine js & creating non blocking user interfaces
Spine js & creating non blocking user interfaces
 
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
 
Angular.js is super cool
Angular.js is super coolAngular.js is super cool
Angular.js is super cool
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Engine
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Angular JS deep dive
Angular JS deep diveAngular JS deep dive
Angular JS deep dive
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 

Dernier

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 

Dernier (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 

AngularJS and SPA

  • 1. AngularJS & SPA Lorenzo Dematte' For 33Dev @ Muse
  • 2. A) server-side generator, “forms” like (aspx, Jsp/Jsf) B) server-side templating (Haml, Mustache, Smarty) C) server-side MVC frameworks D) jQuery E) Another Javascript framework A= ?? B = ?? C = ?? D = ?? E = ?? What are you using to build web applications?
  • 3. (the only image in this slide set. Now we can move on..)
  • 4. What is AngularJS? A complete framework for rich SPA applications
  • 5. What is a SPA? ● Single Page Application ● Client side (with server-side help) ● Rich, responsive, fast ● Desktop-like experience ● “Like the big ones” (Twitter, FB, Gmail)
  • 6. SPA technically ● HTML5 + JS ● Service ● More likely: – An MVC/MVVM client framework – Lightweight REST/Json service(s) ● Even Json non-relational DBs!
  • 8. AngularJS vs. jQuery ● Don't design your page, and then change it with DOM manipulations ● The view is the "official record" ● → Data binding – The “Angular” way
  • 9. <!DOCTYPE html> <html data-ng-app="myapp"> <head> <title>Foo Car rental</title> <script src="scripts/jquery-1.9.1.min.js"></script> <script src="scripts/angular.min.js"></script> <script src="scripts/myapp.js"></script> <body> ... Name: <input type=”text” ng-model=”name” /> {{ name }} 1: Directives and data-binding
  • 11. More directives: ng-repeat, expression, filters <div ng-init="friends = [ {name:'John', age:25, gender:'boy'}, {name:'Jessie', age:30, gender:'girl'}, {name:'Johanna', age:28, gender:'girl'}, {name:'Joy', age:15, gender:'girl'}, {name:'Mary', age:28, gender:'girl'}, {name:'Peter', age:95, gender:'boy'}, {name:'Sebastian', age:50, gender:'boy'}, {name:'Erika', age:27, gender:'girl'}, {name:'Patrick', age:40, gender:'boy'}, {name:'Samantha', age:60, gender:'girl'} ]"> I have {{friends.length}} friends. They are: <input type="search" ng-model="q" placeholder="filter friends..." /> <ul class="example-animate-container"> <li class="animate-repeat" ng-repeat="friend in friends | filter:q"> [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old. </li> </ul> </div>
  • 13. Filters <div>{{ 12345.67 | currency }}</div> <div>{{ 1288323623006 | date:"mediumDate" }}</div> <ul ng-repeat="r in result.results | orderBy:sortBy"> <ul ng-repeat="r in result.results | filter:searchTerm | limitTo:10” > (custom filters) app.filter("orru", function(){ return function(text, length){ return text; // Do nothing } });
  • 15. 2: Views, Controller, Scope View Data
  • 16. 2: Views, Controller, Scope View Data Html Javascript objects/ JSON/something remote
  • 17. 2: Views, Controller, Scope View Data Html Javascript objects/ JSON/something remote
  • 18. 2: Views, Controller, Scope View Data (Model) ViewModel (bi-directional) binding
  • 19. 2: Views, Controller, Scope View Data (Model) Controller Update (query) Input (select)
  • 20. 2: Views, Controller, Scope View Data (Model) $scope (bi-directional) binding Controller
  • 21. Controllers <!DOCTYPE html> <html data-ng-app="myapp"> <head> <title>Foo Car rental</title> <script src="scripts/jquery-1.9.1.min.js"></script> <script src="scripts/angular.min.js"></script> <script src="scripts/myapp.js"></script> <body> <div class="container-narrow"> <div data-ng-controller="SomeController"> <div class="masthead" data-ng-show="showNavigation()"> ... Name: <input type=”text” ng-model=”name” /> {{ name }}
  • 22. Controllers var myApp = angular.module("myApp", []); myApp.controller('SomeController', function ($scope, someService) { $scope.name = “Pippo”; $scope.showNavigation = function() { if (pathUnder("/login") || pathUnder("/registration")) return false; else return true; }; });
  • 25. Modules and dependency injection var myApp = angular.module("myApp", []); myApp.controller('SomeController', function ($scope, someService) { $scope.name = “Pippo”; $scope.showNavigation = function() { if (pathUnder("/login") || pathUnder("/registration")) return false; else return true; }; }); ???
  • 26. Routes App.config(function ($routeProvider) { $routeProvider. when('/', { controller: 'HomeController', templateUrl: 'partials/home.html' }). when('/user-info', { controller: 'UserController', templateUrl: 'partials/user-info.html' }). when('/login', { controller: 'LoginController', templateUrl: 'partials/login.html' }). when('/registration', { controller: 'LoginController', templateUrl: 'partials/registration.html' }). when('/invalid-server-response', { controller: 'UserController', templateUrl: 'partials/invalid-server-response.html' }). when('/error', { controller: 'UserController', templateUrl: 'partials/error.html' }). otherwise({ redirectTo: '/' }); });
  • 27. Routes and views <div data-ng-view=""></div> “Partials”
  • 28. Services angular.module("MiniResources", [], ["$provide", function($provide) { $provide.value("miniResources", { nameRequired : "E' necessario specificare un nome", fieldAdded: "Campo aggiunto con successo", emptyField: "<vuoto>", startFlowQuestion: "Sei sicuro di voler cominicare un flusso", startFlow: "Comincia un nuovo flusso", yes: "Si", no: "No", back: "Torna indietro", all: "Tutti", processing: "Sto elaborando", error: "Errore", close: "Chiudi" }); }]);
  • 29. Service usage ● They are injected! miniApp.controller("StepController", function ($scope, …, miniResources)
  • 31. 4: Custom directives app.directive('ngContent', function ($parse) { return { restrict: 'A', require: '?ngModel', link: function (scope, element, attrs) { if (attrs.ngModel && element.text()) { $parse(attrs.ngModel).assign(scope, element.text()); } scope.$watch(attrs.ngModel, function(value) { element.text(value); }); } }; }); Where? require: '^parentDirective' will give you access to the parentDirective ^ -- Look for the controller on parent elements, not just on the local scope ? -- Don't raise an error if the controller isn't found
  • 33. 5: UI
  • 34. UI elements in Angular <h4>Static arrays</h4> <pre>Model: {{selected | json}}</pre> <input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue | limitTo:8" class="form-control"> <h4>Asynchronous results</h4> <pre>Model: {{asyncSelected | json}}</pre> <input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue) | filter:$viewValue" typeahead-loading="loadingLocations" class="form-control">
  • 36. ...but... in the real world? ● #1: Javascript vs. “Security through obscurity” (F12 - but it is actually good because...) ● #2: you have to design a SPA keeping #1 in mind ● #3: SPA are almost never “single page” ● #4: HTTPS and/or OAuth!
  • 37. In the real world... ● You almost always “blur” the lines – Server-side generation AND client-side rendering – Multiple pages for multiple roles – Use your server!