SlideShare una empresa de Scribd logo
1 de 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!

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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)
 

Último

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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...Neo4j
 
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 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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 StreamsRoshan Dwivedi
 
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 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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 WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

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!