SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
AngularJS
AN INTRODUCTION
Introduction to the AngularJS framework
AngularJS
• Javascript framework for writing frontend web
apps
– DOM manipulation, input validation, server
communication, URL management, etc.
• Inspired by the Model-View-Controller pattern
– HTML templating approach with two-way binding
• Focus on supporting large and single page
applications
– modules, reusable components, etc.
• Widely used
– a major rewrite is coming out (version 2)
– we will use version 1.x
22/04/2016 AngularJS: an introduction 2
AngularJS
• Javascript framework for writing frontend web
apps
– DOM manipulation, input validation, server
communication, URL management, etc.
• Inspired by the Model-View-Controller pattern
– HTML templating approach with two-way binding
• Focus on supporting large and single page
applications
– modules, reusable components, etc.
• Widely used
– a major rewrite is coming out (version 2)
– we will use version 1.x
22/04/2016 AngularJS: an introduction 3
See:
“Background”
section
AngularJS
• Developed by Google
• Website: https://angularjs.org/
– download version 1.x
• Included in our “starter kit”
– https://github.com/SoNet-2016/starter-kit
22/04/2016 AngularJS: an introduction 4
Concepts and Terminology
Template HTML with additional markup used to describe what should
be displayed
Directive Allows a developer to extend HTML with her own elements
and attributes
Scope Context where the model data is stored so that templates
and controllers can access
Compiler Processes the template to generate HTML for the browser
Data Binding Syncing of data between the Scope and the HTML (two-way)
Dependency
Injection
Fetching and setting up all the functionality needed by a
component
Module A container for parts of an application
Service Reusable functionality available for any view
22/04/2016 AngularJS: an introduction 5
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>What's your name?</title>
</head>
<body>
<div>
<label>Name</label>
<input type="text" ng-model="name" placeholder="Enter
your name">
<h1>Hello {{ name }}!</h1>
</div>
<script src="./angular.min.js"></script>
</body>
</html>
22/04/2016 AngularJS: an introduction 6
Example 1
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>What's your name?</title>
</head>
<body>
<div>
<label>Name</label>
<input type="text" ng-model="name" placeholder="Enter
your name">
<h1>Hello {{ name }}!</h1>
</div>
<script src="./angular.min.js"></script>
</body>
</html>
22/04/2016 AngularJS: an introduction 7
script loads and runs when the
browser signals that the context
is ready
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>What's your name?</title>
</head>
<body>
<div>
<label>Name</label>
<input type="text" ng-model="name" placeholder="Enter
your name">
<h1>Hello {{ name }}!</h1>
</div>
<script src="./angular.min.js"></script>
</body>
</html>
22/04/2016 AngularJS: an introduction 8
Angular scans the HTML
looking for the ng-app
attribute. It creates a scope.
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>What's your name?</title>
</head>
<body>
<div>
<label>Name</label>
<input type="text" ng-model="name" placeholder="Enter
your name">
<h1>Hello {{ name }}!</h1>
</div>
<script src="./angular.min.js"></script>
</body>
</html>
22/04/2016 AngularJS: an introduction 9
The compiler scans the DOM for
templating markups. Then, it fills
them with info from the scope.
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>What's your name?</title>
</head>
<body>
<div>
<label>Name</label>
<input type="text" ng-model="name" placeholder="Enter
your name">
<h1>Hello {{ name }}!</h1>
</div>
<script src="./angular.min.js"></script>
</body>
</html>
22/04/2016 AngularJS: an introduction 10
name is replaced with the
value inserted in the <input>
Two-way
binding
Directives and Data Binding
• Directives
– markers on a DOM element that tell Angular’s HTML
compiler to attach a specific behavior to that
element
– <html lang="en" ng-app>
– <input type="text" ng-model="name" …>
• Data Binding
– the automatic synchronization of data between the
model and the view components
• {{ name }}
22/04/2016 AngularJS: an introduction 11
Other Built-in Directives
• ng-src | ng-href
– delay <img> src | <a> href interpretation to get
handled by Angular
• ng-repeat
– instantiate a template once per item from a
collection
22/04/2016 AngularJS: an introduction 12
<div data-ng-init="names = ['Luigi', 'Laura', 'Teo', 'Gabriella']">
<h3>Loop through names with ng-repeat</h3>
<ul>
<li ng-repeat="name in names">{{ name }}</li>
</ul>
</div>
Example 2
Other Built-in Directives
• ng-show/ng-hide
– show/hide DOM elements according to a given
expression
• ng-if
– include an element in the DOM if the subsequent
expression is true
• ng-click
– Angular version of HTML’s onclick
– execute a given operation when the element is
clicked
22/04/2016 AngularJS: an introduction 13
Filters
• Formats the value of an expression for display
to the user
– {{ name | uppercase }}
• Keeps formatting into the presentation
• Syntax
– {{ expression | filter }}
– {{ expression | filter1 | filter2 }}
– {{ expression | filter:argument }}
22/04/2016 AngularJS: an introduction 14
Controllers
• A controller should be concerned – only! - with
– consuming data,
– preparing it for the view, and
– transmitting it to service for processing
• Best practices
– services are responsible to hold the model and
communicate with a server
– declarations should manipulate the DOM
– views do not have to know about their controller
– a controller definitely does not want to know about
its view
22/04/2016 AngularJS: an introduction 15
Controllers
• A JavaScript function
• It defines a new $scope that may
– contain data (properties)
– specify some behaviors (methods)
• It should contain only the logic needed for a
single view
– i.e., each view should have one controller (and
viceversa)
22/04/2016 AngularJS: an introduction 16
<!DOCTYPE html>
<html lang="en" ng-app="sonetExample" >
<head>
<meta charset="UTF-8">
<title>Introducing... Controllers!</title>
</head>
<body ng-controller="MyCtrl">
<div>
<label>Name</label>
<input type="text" ng-model="name" ...>
<h1>{{ greeting }} {{name}}!</h1>
</div>
[...]
22/04/2016 AngularJS: an introduction 17
HTML
angular.module("sonetExample", [])
.controller('MyCtrl', function ($scope) {
$scope.name = "";
$scope.greeting = "Ciao";
})
JS
module
controller
Example 3
Modules
• Container to collect and organize components
– in a modular way
• Multiple modules can exist in an application
– “main” module (ng-app)
– service modules, controller modules, etc.
• Best practices
– a module for each feature
– a module for each reusable component (especially
directives and filters)
– an application level module which depends on the above
modules and contains any initialization code
22/04/2016 AngularJS: an introduction 18
The Scope ($scope)
• The “glue” between a controller and a template
• An execution context for expressions like
{{ pizza.name }}
• Scopes are arranged in a hierarchical structure that
mimic the DOM structure of the application
• Scopes can watch expressions and propagate
events
• $rootScope
– every application has ONE root scope, all other scopes are
its descendant
22/04/2016 AngularJS: an introduction 19
Routing
• Single page applications need routing
– to mimic static addresses (http://mysite.com/...)
– to manage browser history
• Goal: load different views into the single page
app
22/04/2016 AngularJS: an introduction 20
ngRoute
• Angular API for routing
• Provides
– a directive to indicate where view component should
be inserted in the template (ngView)
– a service that watches window.location for changes
and updates the displayed view ($route)
– a configuration that allows the user to specify the
URL to be used for a specific view ($routeProvider)
• It is located in a dedicated js file
– not in angular.(min).js
22/04/2016 AngularJS: an introduction 21
Using ngRoute
• In a template
<div ng-view></div>
• In your Angular module, add ngRoute as a
dependency
angular.module('sonetExample', [ngRoute])
• Configure the routing table in a config block
.config(['$routeProvider',
function($routeProvider) {
…
}])
22/04/2016 AngularJS: an introduction 22
Example 4
Passing parameters in URLs
URLs:
– #/pizzas/my-pizza
– #/pizzas/another-pizza
Routing table configuration:
22/04/2016 AngularJS: an introduction 23
.config(['$routeProvider', function ($routeProvider){
$routeProvider
.when('/pizzas/:pizzaId', {
templateUrl: 'single-pizza.html',
controller: 'PizzaCtrl',
})
[...]
}])
JS
Passing parameters in URLs
Controller:
22/04/2016 AngularJS: an introduction 24
.controller('PizzaCtrl', ['$routeParams',
function ($routeParams) {
$routeParams.pizzaId
// will be my-pizza or another-pizza
})
JS
Services
• Responsible to hold the
model and communicate
with a server
• Singleton objects that
are instantiated only
once per app and lazy
loaded
– controllers are
instantiated only when
they are needed and
discarded otherwise
22/04/2016 AngularJS: an introduction 25
Built-in Services
• Server communication
– $http, $resource, …
• Wrapping DOM access
– $location, $window, $document, …
• JavaScript functionality
– $animate, $log, …
22/04/2016 AngularJS: an introduction 26
The $http Service
• Uses the XMLHttpRequest object (or JSONP) to
communicate with a server
• How it works
– takes a single argument: a configuration object
– returns a promise with two methods: success() and
error()
• It can use the .then() method, too
– it registers a dedicated callback for the success and
error method
22/04/2016 AngularJS: an introduction 27
The $http Service
22/04/2016 AngularJS: an introduction 28
$http({
method: 'GET',
url: '/someUrl'})
.success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
})
.error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
})
JS
promise
callbacks
The $http Service
22/04/2016 AngularJS: an introduction 29
var sonet = angular.module('sonetExample', []);
sonet.controller('MyCtrl', ['$scope', '$http',
function ($scope, $http) {
var promise = $http.get('/pizzas.json');
promise.success(function(data) {
$scope.pizzas = data;
});
}
]);
JS
The $http Service
22/04/2016 AngularJS: an introduction 30
var sonet = angular.module('sonetExample', []);
sonet.controller('MyCtrl', ['$scope', '$http',
function ($scope, $http) {
var promise = $http.get('/pizzas.json');
promise.success(function(data) {
$scope.pizzas = data;
});
}
]);
JS
Shortcut methods:
.get(), .post(), .put(), .delete(), etc.
$http in a Custom Service
22/04/2016 AngularJS: an introduction 31
// custom service
sonet.factory('Pizza', function($http) {
var pizzaService = {
getData: function () {
return $http.get('/pizzas.json')
.then(function (response) {
return response.data;
});
}
};
return pizzaService;
})
// controller
sonet.controller('PizzaCtrl', ['$scope', 'Pizza',
function ($scope, Pizza) {
Pizza.getData().then(function(pizzaList) {
$scope.pizzas = pizzaList;
});
}
]);
JS
Example 5
The $resource Service
• Replace the "low level" $http service
– it has methods with high-level behaviors
– but the server URLs must be RESTful
• REST: REpresentational State Transfer
– works on the concept of “resource”
• CRUD: Create, Read, Update and Delete
read a collection of resources: GET /pizzas
read a single resource: GET /pizzas/:id
add a new resource: POST /pizzas
update an existing resource: PUT /pizzas/:id
delete an existing resource: DELETE /pizzas/:id
22/04/2016 AngularJS: an introduction 32
The $resource Service
• Requires the ngResource module to be installed
• No callbacks needed!
– e.g., $scope.pizzas = pizzaService.query();
• Available methods
– get(), method: GET, single resource
– query(), method: GET, is array (collection)
– save(), method: POST
– remove(), method: DELETE,
– delete(), method: DELETE
22/04/2016 AngularJS: an introduction 33
Custom Directives
• Application specific
– replace HTML tags with “functional” tags you define
e.g., DatePicker, Accordion, ...
• Naming
• Camel case naming (ngRepeat)
– automatically mapped to ng-repeat, data-ng-
repeat in the templates
e.g., <div ng-repeat></div>
22/04/2016 AngularJS: an introduction 34
Custom Directives
• A directive returns an “object” (directive
definition) with several properties
– details:
https://docs.angularjs.org/api/ng/service/$compile
22/04/2016 AngularJS: an introduction 35
var sonet = angular.module('sonetExample', []);
sonet.directive('helloHeader', function() {
return {
restrict: 'E',
template: '<h2>Hello World!</h2>'
};
});
JS
Custom Directives
22/04/2016 AngularJS: an introduction 36
var sonet = angular.module('sonetExample', []);
sonet.directive('helloHeader', function() {
return {
restrict: 'E',
template: '<h2>Hello World!</h2>'
};
});
JS
Restricts the directive to a specific HTML "item".
If omitted, the defaults (Elements and Attributes) are
used.
Custom Directives
22/04/2016 AngularJS: an introduction 37
var sonet = angular.module('sonetExample', []);
sonet.directive('helloHeader', function() {
return {
restrict: 'E',
template: '<h2>Hello World!</h2>'
};
});
JS
replace or wrap the contents of an
element with this template
Compile and Link
• Named after the two phases Angular uses to create
the live view for your application
• Compile
– looks for all the directives and transforms the DOM
accordingly, then calls the compile function (if it exists)
• Link
– makes the view dynamic via directive link functions
– the link functions typically create listeners on the DOM or
the model; these listeners keep the view and the model in
sync at all times
– scopes are attached to the compiled link functions, and
the directive becomes live through data binding
22/04/2016 AngularJS: an introduction 38
Link Function: Example
22/04/2016 AngularJS: an introduction 39
var sonet = angular.module('sonetExample', []);
sonet.directive('backButton', ['$window', function ($window) {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem.bind('click', function () {
$window.history.back();
});
}
};
}])
JS
BEST PRACTICES
Other best practices in AngularJS
22/04/2016 AngularJS: an introduction 40
A dot in the model
"There should always be a dot in your model"
Parent scope: $scope.name = "Anon"
Child scope: <input type="text" ng-model="name">
The application will display "Anon" initially, but once the
user change the value a name will be created on the child
scope and the binding will read and write that value.
The parent's name will remain "Anon".
This can cause problems in large applications.
To avoid them:
<input type="text" ng-model="person.name">
22/04/2016 AngularJS: an introduction 41
camelCase vs dash-case
You can use variable named like
my-variable
myVariable
• The latter can cause problems in HTML
– it is case-insensitive
• Angular solution: use either, it will map them to
the same thing
Use dash-case in HTML and camelCase in JavaScript
22/04/2016 AngularJS: an introduction 42
BACKGROUND
Concepts behind AngularJS. Briefly.
22/04/2016 AngularJS: an introduction 43
Model-View-Controller Pattern
• Model
– manage the application data
– e.g., Javascript objects representing pizza names,
pictures, comments, etc.
• View
– what the web page looks like
– e.g., HTML/CSS for viewing pizzas, view pizza photos, etc.
• Controller
– fetch models and control views, handle user interactions
• e.g., Javascript code for DOM event handlers, server
communication, etc.
22/04/2016 AngularJS: an introduction 44
View Generation (frontend)
• HTML/CSS is generated in the frontend
• Templates are commonly used
• Basic idea
– write a HTML document containing parts of the page
that do not change
– add some code that generate the parts computed for
each page
– the template is expanded by executing the code and
substituting the result into the document
• Angular has a rich templating language
22/04/2016 AngularJS: an introduction 45
Models in Angular
• Angular does not specify model data
– i.e., as Javascript objects
• It provides support for fetching data from a
web server
– support for REST APIs
– JSON is frequently used
22/04/2016 AngularJS: an introduction 46
Single Page Applications
• Web applications in which the appropriate
resource is dynamically loaded and added to the
page when necessary
• Instead of changing the page, a view inside the
page is changed
– “everything is in a single web page”
– exploits the templating approach
• The entire page does not reload
– it uses AJAX
22/04/2016 AngularJS: an introduction 47
Single Page Applications
Problems:
1. mimic static addresses (http://mysite.com/...) and
manage browser history
2. mix HTML and JavaScript
3. handle AJAX callbacks
Solutions:
[managed by Angular and similar frameworks]
1. routing (http://mysite.com/#...)
2. templating
3. server backend + HTML5 functionalities
22/04/2016 AngularJS: an introduction 48
References
• AngularJS official guide
– https://docs.angularjs.org/guide
• AngularJS API documentation
– https://docs.angularjs.org/api
• AngularJS in 60 minutes [video]
– https://www.youtube.com/watch?v=i9MHigUZKEM
• Learn Angular in your browser
– http://angular.codeschool.com/
22/04/2016 AngularJS: an introduction 49
Questions?
01QYAPD SOCIAL NETWORKING: TECHNOLOGIES
AND APPLICATIONS
Luigi De Russis
luigi.derussis@polito.it
License
• This work is licensed under the Creative Commons “Attribution-
NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License.
• You are free:
– to Share - to copy, distribute and transmit the work
– to Remix - to adapt the work
• Under the following conditions:
– Attribution - You must attribute the work in the manner specified by the
author or licensor (but not in any way that suggests that they endorse you
or your use of the work).
– Noncommercial - You may not use this work for commercial purposes.
– Share Alike - If you alter, transform, or build upon this work, you may
distribute the resulting work only under the same or similar license to this
one.
• To view a copy of this license, visit
http://creativecommons.org/license/by-nc-sa/3.0/
22/04/2016 AngularJS: an introduction 51

Contenu connexe

Tendances

Tendances (20)

Angular 8
Angular 8 Angular 8
Angular 8
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기 스프링처럼 JDBC 리팩터링하기
스프링처럼 JDBC 리팩터링하기
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
React introduction
React introductionReact introduction
React introduction
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Vue.js
Vue.jsVue.js
Vue.js
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 

En vedette

PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...Luigi De Russis
 
AmI 2016 - Python basics
AmI 2016 - Python basicsAmI 2016 - Python basics
AmI 2016 - Python basicsLuigi De Russis
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Luigi De Russis
 
AmI 2017 - Python basics
AmI 2017 - Python basicsAmI 2017 - Python basics
AmI 2017 - Python basicsLuigi De Russis
 
Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic WebLuigi De Russis
 
Semantic Web: an introduction
Semantic Web: an introductionSemantic Web: an introduction
Semantic Web: an introductionLuigi De Russis
 
Interacting with Smart Environments - Ph.D. Thesis Presentation
Interacting with Smart Environments - Ph.D. Thesis PresentationInteracting with Smart Environments - Ph.D. Thesis Presentation
Interacting with Smart Environments - Ph.D. Thesis PresentationLuigi De Russis
 
Cnc programming handbook - Peter Schmid
Cnc programming handbook - Peter SchmidCnc programming handbook - Peter Schmid
Cnc programming handbook - Peter SchmidMaxwell Chikara
 
CNC Programming
CNC ProgrammingCNC Programming
CNC ProgrammingMal Moran
 
Habit 3 Put First things First
Habit 3 Put First things FirstHabit 3 Put First things First
Habit 3 Put First things Firstlynettecallaghan
 
Begin With The End In Mind 1
Begin With The End In Mind 1Begin With The End In Mind 1
Begin With The End In Mind 1danielleisathome
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 
AmI 2017 - Python intermediate
AmI 2017 - Python intermediateAmI 2017 - Python intermediate
AmI 2017 - Python intermediateLuigi De Russis
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101Luigi De Russis
 

En vedette (17)

PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...PowerOnt: an ontology-based approach for power consumption estimation in Smar...
PowerOnt: an ontology-based approach for power consumption estimation in Smar...
 
AmI 2016 - Python basics
AmI 2016 - Python basicsAmI 2016 - Python basics
AmI 2016 - Python basics
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)
 
AmI 2017 - Python basics
AmI 2017 - Python basicsAmI 2017 - Python basics
AmI 2017 - Python basics
 
Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic Web
 
Semantic Web: an introduction
Semantic Web: an introductionSemantic Web: an introduction
Semantic Web: an introduction
 
Interacting with Smart Environments - Ph.D. Thesis Presentation
Interacting with Smart Environments - Ph.D. Thesis PresentationInteracting with Smart Environments - Ph.D. Thesis Presentation
Interacting with Smart Environments - Ph.D. Thesis Presentation
 
Cnc programming handbook - Peter Schmid
Cnc programming handbook - Peter SchmidCnc programming handbook - Peter Schmid
Cnc programming handbook - Peter Schmid
 
CNC Programming
CNC ProgrammingCNC Programming
CNC Programming
 
cAdaptive control
cAdaptive controlcAdaptive control
cAdaptive control
 
Habit 3 Put First things First
Habit 3 Put First things FirstHabit 3 Put First things First
Habit 3 Put First things First
 
Put First Things First
Put First Things FirstPut First Things First
Put First Things First
 
Begin With The End In Mind 1
Begin With The End In Mind 1Begin With The End In Mind 1
Begin With The End In Mind 1
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 
AmI 2017 - Python intermediate
AmI 2017 - Python intermediateAmI 2017 - Python intermediate
AmI 2017 - Python intermediate
 
Be Proactive 1
Be Proactive 1Be Proactive 1
Be Proactive 1
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101
 

Similaire à AngularJS: An Introduction to the Framework

AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosLearnimtactics
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaBharat Makwana
 
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
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and conceptsSuresh Patidar
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB
 

Similaire à AngularJS: An Introduction to the Framework (20)

AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
AngularJS
AngularJSAngularJS
AngularJS
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
AngularJS
AngularJSAngularJS
AngularJS
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat Makwana
 
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
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
 
Angular js
Angular jsAngular js
Angular js
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 

Plus de Luigi De Russis

Assessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Assessing Virtual Assistant Capabilities with Italian Dysarthric SpeechAssessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Assessing Virtual Assistant Capabilities with Italian Dysarthric SpeechLuigi De Russis
 
Semantic Web: an Introduction
Semantic Web: an IntroductionSemantic Web: an Introduction
Semantic Web: an IntroductionLuigi De Russis
 
Ambient Intelligence: An Overview
Ambient Intelligence: An OverviewAmbient Intelligence: An Overview
Ambient Intelligence: An OverviewLuigi De Russis
 
LAM 2015 - Social Networks Technologies
LAM 2015 - Social Networks TechnologiesLAM 2015 - Social Networks Technologies
LAM 2015 - Social Networks TechnologiesLuigi De Russis
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basicsLuigi De Russis
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Living in Smart Environments - 3rd year PhD Report
Living in Smart Environments - 3rd year PhD ReportLiving in Smart Environments - 3rd year PhD Report
Living in Smart Environments - 3rd year PhD ReportLuigi De Russis
 
Semantic Web: an introduction
Semantic Web: an introductionSemantic Web: an introduction
Semantic Web: an introductionLuigi De Russis
 
Social Network Technologies
Social Network TechnologiesSocial Network Technologies
Social Network TechnologiesLuigi De Russis
 
Living in Smart Environments - 2nd year PhD Report
Living in Smart Environments - 2nd year PhD ReportLiving in Smart Environments - 2nd year PhD Report
Living in Smart Environments - 2nd year PhD ReportLuigi De Russis
 
Installing OpenCV 2.4.x with Qt
Installing OpenCV 2.4.x with QtInstalling OpenCV 2.4.x with Qt
Installing OpenCV 2.4.x with QtLuigi De Russis
 
dWatch: a Personal Wrist Watch for Smart Environments
dWatch: a Personal Wrist Watch for Smart EnvironmentsdWatch: a Personal Wrist Watch for Smart Environments
dWatch: a Personal Wrist Watch for Smart EnvironmentsLuigi De Russis
 
Introduction to OpenCV 2.3.1
Introduction to OpenCV 2.3.1Introduction to OpenCV 2.3.1
Introduction to OpenCV 2.3.1Luigi De Russis
 
Installing OpenCV 2.3.1 with Qt
Installing OpenCV 2.3.1 with QtInstalling OpenCV 2.3.1 with Qt
Installing OpenCV 2.3.1 with QtLuigi De Russis
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introductionLuigi De Russis
 
Domotics: an open approach
Domotics: an open approachDomotics: an open approach
Domotics: an open approachLuigi De Russis
 
Rule Builder at ISAmI 2011
Rule Builder at ISAmI 2011Rule Builder at ISAmI 2011
Rule Builder at ISAmI 2011Luigi De Russis
 

Plus de Luigi De Russis (20)

Assessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Assessing Virtual Assistant Capabilities with Italian Dysarthric SpeechAssessing Virtual Assistant Capabilities with Italian Dysarthric Speech
Assessing Virtual Assistant Capabilities with Italian Dysarthric Speech
 
Semantic Web: an Introduction
Semantic Web: an IntroductionSemantic Web: an Introduction
Semantic Web: an Introduction
 
Ambient Intelligence: An Overview
Ambient Intelligence: An OverviewAmbient Intelligence: An Overview
Ambient Intelligence: An Overview
 
LAM 2015 - Social Networks Technologies
LAM 2015 - Social Networks TechnologiesLAM 2015 - Social Networks Technologies
LAM 2015 - Social Networks Technologies
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Living in Smart Environments - 3rd year PhD Report
Living in Smart Environments - 3rd year PhD ReportLiving in Smart Environments - 3rd year PhD Report
Living in Smart Environments - 3rd year PhD Report
 
Semantic Web: an introduction
Semantic Web: an introductionSemantic Web: an introduction
Semantic Web: an introduction
 
Social Network Technologies
Social Network TechnologiesSocial Network Technologies
Social Network Technologies
 
Clean Code
Clean CodeClean Code
Clean Code
 
Living in Smart Environments - 2nd year PhD Report
Living in Smart Environments - 2nd year PhD ReportLiving in Smart Environments - 2nd year PhD Report
Living in Smart Environments - 2nd year PhD Report
 
Introduction to OpenCV
Introduction to OpenCVIntroduction to OpenCV
Introduction to OpenCV
 
Installing OpenCV 2.4.x with Qt
Installing OpenCV 2.4.x with QtInstalling OpenCV 2.4.x with Qt
Installing OpenCV 2.4.x with Qt
 
dWatch: a Personal Wrist Watch for Smart Environments
dWatch: a Personal Wrist Watch for Smart EnvironmentsdWatch: a Personal Wrist Watch for Smart Environments
dWatch: a Personal Wrist Watch for Smart Environments
 
Introduction to OpenCV 2.3.1
Introduction to OpenCV 2.3.1Introduction to OpenCV 2.3.1
Introduction to OpenCV 2.3.1
 
Installing OpenCV 2.3.1 with Qt
Installing OpenCV 2.3.1 with QtInstalling OpenCV 2.3.1 with Qt
Installing OpenCV 2.3.1 with Qt
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introduction
 
Domotics: an open approach
Domotics: an open approachDomotics: an open approach
Domotics: an open approach
 
Rule Builder at ISAmI 2011
Rule Builder at ISAmI 2011Rule Builder at ISAmI 2011
Rule Builder at ISAmI 2011
 

Dernier

4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 

Dernier (20)

4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 

AngularJS: An Introduction to the Framework

  • 2. AngularJS • Javascript framework for writing frontend web apps – DOM manipulation, input validation, server communication, URL management, etc. • Inspired by the Model-View-Controller pattern – HTML templating approach with two-way binding • Focus on supporting large and single page applications – modules, reusable components, etc. • Widely used – a major rewrite is coming out (version 2) – we will use version 1.x 22/04/2016 AngularJS: an introduction 2
  • 3. AngularJS • Javascript framework for writing frontend web apps – DOM manipulation, input validation, server communication, URL management, etc. • Inspired by the Model-View-Controller pattern – HTML templating approach with two-way binding • Focus on supporting large and single page applications – modules, reusable components, etc. • Widely used – a major rewrite is coming out (version 2) – we will use version 1.x 22/04/2016 AngularJS: an introduction 3 See: “Background” section
  • 4. AngularJS • Developed by Google • Website: https://angularjs.org/ – download version 1.x • Included in our “starter kit” – https://github.com/SoNet-2016/starter-kit 22/04/2016 AngularJS: an introduction 4
  • 5. Concepts and Terminology Template HTML with additional markup used to describe what should be displayed Directive Allows a developer to extend HTML with her own elements and attributes Scope Context where the model data is stored so that templates and controllers can access Compiler Processes the template to generate HTML for the browser Data Binding Syncing of data between the Scope and the HTML (two-way) Dependency Injection Fetching and setting up all the functionality needed by a component Module A container for parts of an application Service Reusable functionality available for any view 22/04/2016 AngularJS: an introduction 5
  • 6. <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>What's your name?</title> </head> <body> <div> <label>Name</label> <input type="text" ng-model="name" placeholder="Enter your name"> <h1>Hello {{ name }}!</h1> </div> <script src="./angular.min.js"></script> </body> </html> 22/04/2016 AngularJS: an introduction 6 Example 1
  • 7. <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>What's your name?</title> </head> <body> <div> <label>Name</label> <input type="text" ng-model="name" placeholder="Enter your name"> <h1>Hello {{ name }}!</h1> </div> <script src="./angular.min.js"></script> </body> </html> 22/04/2016 AngularJS: an introduction 7 script loads and runs when the browser signals that the context is ready
  • 8. <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>What's your name?</title> </head> <body> <div> <label>Name</label> <input type="text" ng-model="name" placeholder="Enter your name"> <h1>Hello {{ name }}!</h1> </div> <script src="./angular.min.js"></script> </body> </html> 22/04/2016 AngularJS: an introduction 8 Angular scans the HTML looking for the ng-app attribute. It creates a scope.
  • 9. <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>What's your name?</title> </head> <body> <div> <label>Name</label> <input type="text" ng-model="name" placeholder="Enter your name"> <h1>Hello {{ name }}!</h1> </div> <script src="./angular.min.js"></script> </body> </html> 22/04/2016 AngularJS: an introduction 9 The compiler scans the DOM for templating markups. Then, it fills them with info from the scope.
  • 10. <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>What's your name?</title> </head> <body> <div> <label>Name</label> <input type="text" ng-model="name" placeholder="Enter your name"> <h1>Hello {{ name }}!</h1> </div> <script src="./angular.min.js"></script> </body> </html> 22/04/2016 AngularJS: an introduction 10 name is replaced with the value inserted in the <input> Two-way binding
  • 11. Directives and Data Binding • Directives – markers on a DOM element that tell Angular’s HTML compiler to attach a specific behavior to that element – <html lang="en" ng-app> – <input type="text" ng-model="name" …> • Data Binding – the automatic synchronization of data between the model and the view components • {{ name }} 22/04/2016 AngularJS: an introduction 11
  • 12. Other Built-in Directives • ng-src | ng-href – delay <img> src | <a> href interpretation to get handled by Angular • ng-repeat – instantiate a template once per item from a collection 22/04/2016 AngularJS: an introduction 12 <div data-ng-init="names = ['Luigi', 'Laura', 'Teo', 'Gabriella']"> <h3>Loop through names with ng-repeat</h3> <ul> <li ng-repeat="name in names">{{ name }}</li> </ul> </div> Example 2
  • 13. Other Built-in Directives • ng-show/ng-hide – show/hide DOM elements according to a given expression • ng-if – include an element in the DOM if the subsequent expression is true • ng-click – Angular version of HTML’s onclick – execute a given operation when the element is clicked 22/04/2016 AngularJS: an introduction 13
  • 14. Filters • Formats the value of an expression for display to the user – {{ name | uppercase }} • Keeps formatting into the presentation • Syntax – {{ expression | filter }} – {{ expression | filter1 | filter2 }} – {{ expression | filter:argument }} 22/04/2016 AngularJS: an introduction 14
  • 15. Controllers • A controller should be concerned – only! - with – consuming data, – preparing it for the view, and – transmitting it to service for processing • Best practices – services are responsible to hold the model and communicate with a server – declarations should manipulate the DOM – views do not have to know about their controller – a controller definitely does not want to know about its view 22/04/2016 AngularJS: an introduction 15
  • 16. Controllers • A JavaScript function • It defines a new $scope that may – contain data (properties) – specify some behaviors (methods) • It should contain only the logic needed for a single view – i.e., each view should have one controller (and viceversa) 22/04/2016 AngularJS: an introduction 16
  • 17. <!DOCTYPE html> <html lang="en" ng-app="sonetExample" > <head> <meta charset="UTF-8"> <title>Introducing... Controllers!</title> </head> <body ng-controller="MyCtrl"> <div> <label>Name</label> <input type="text" ng-model="name" ...> <h1>{{ greeting }} {{name}}!</h1> </div> [...] 22/04/2016 AngularJS: an introduction 17 HTML angular.module("sonetExample", []) .controller('MyCtrl', function ($scope) { $scope.name = ""; $scope.greeting = "Ciao"; }) JS module controller Example 3
  • 18. Modules • Container to collect and organize components – in a modular way • Multiple modules can exist in an application – “main” module (ng-app) – service modules, controller modules, etc. • Best practices – a module for each feature – a module for each reusable component (especially directives and filters) – an application level module which depends on the above modules and contains any initialization code 22/04/2016 AngularJS: an introduction 18
  • 19. The Scope ($scope) • The “glue” between a controller and a template • An execution context for expressions like {{ pizza.name }} • Scopes are arranged in a hierarchical structure that mimic the DOM structure of the application • Scopes can watch expressions and propagate events • $rootScope – every application has ONE root scope, all other scopes are its descendant 22/04/2016 AngularJS: an introduction 19
  • 20. Routing • Single page applications need routing – to mimic static addresses (http://mysite.com/...) – to manage browser history • Goal: load different views into the single page app 22/04/2016 AngularJS: an introduction 20
  • 21. ngRoute • Angular API for routing • Provides – a directive to indicate where view component should be inserted in the template (ngView) – a service that watches window.location for changes and updates the displayed view ($route) – a configuration that allows the user to specify the URL to be used for a specific view ($routeProvider) • It is located in a dedicated js file – not in angular.(min).js 22/04/2016 AngularJS: an introduction 21
  • 22. Using ngRoute • In a template <div ng-view></div> • In your Angular module, add ngRoute as a dependency angular.module('sonetExample', [ngRoute]) • Configure the routing table in a config block .config(['$routeProvider', function($routeProvider) { … }]) 22/04/2016 AngularJS: an introduction 22 Example 4
  • 23. Passing parameters in URLs URLs: – #/pizzas/my-pizza – #/pizzas/another-pizza Routing table configuration: 22/04/2016 AngularJS: an introduction 23 .config(['$routeProvider', function ($routeProvider){ $routeProvider .when('/pizzas/:pizzaId', { templateUrl: 'single-pizza.html', controller: 'PizzaCtrl', }) [...] }]) JS
  • 24. Passing parameters in URLs Controller: 22/04/2016 AngularJS: an introduction 24 .controller('PizzaCtrl', ['$routeParams', function ($routeParams) { $routeParams.pizzaId // will be my-pizza or another-pizza }) JS
  • 25. Services • Responsible to hold the model and communicate with a server • Singleton objects that are instantiated only once per app and lazy loaded – controllers are instantiated only when they are needed and discarded otherwise 22/04/2016 AngularJS: an introduction 25
  • 26. Built-in Services • Server communication – $http, $resource, … • Wrapping DOM access – $location, $window, $document, … • JavaScript functionality – $animate, $log, … 22/04/2016 AngularJS: an introduction 26
  • 27. The $http Service • Uses the XMLHttpRequest object (or JSONP) to communicate with a server • How it works – takes a single argument: a configuration object – returns a promise with two methods: success() and error() • It can use the .then() method, too – it registers a dedicated callback for the success and error method 22/04/2016 AngularJS: an introduction 27
  • 28. The $http Service 22/04/2016 AngularJS: an introduction 28 $http({ method: 'GET', url: '/someUrl'}) .success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available }) .error(function(data, status, headers, config) { // called asynchronously if an error occurs // or server returns response with an error status. }); }) JS promise callbacks
  • 29. The $http Service 22/04/2016 AngularJS: an introduction 29 var sonet = angular.module('sonetExample', []); sonet.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) { var promise = $http.get('/pizzas.json'); promise.success(function(data) { $scope.pizzas = data; }); } ]); JS
  • 30. The $http Service 22/04/2016 AngularJS: an introduction 30 var sonet = angular.module('sonetExample', []); sonet.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) { var promise = $http.get('/pizzas.json'); promise.success(function(data) { $scope.pizzas = data; }); } ]); JS Shortcut methods: .get(), .post(), .put(), .delete(), etc.
  • 31. $http in a Custom Service 22/04/2016 AngularJS: an introduction 31 // custom service sonet.factory('Pizza', function($http) { var pizzaService = { getData: function () { return $http.get('/pizzas.json') .then(function (response) { return response.data; }); } }; return pizzaService; }) // controller sonet.controller('PizzaCtrl', ['$scope', 'Pizza', function ($scope, Pizza) { Pizza.getData().then(function(pizzaList) { $scope.pizzas = pizzaList; }); } ]); JS Example 5
  • 32. The $resource Service • Replace the "low level" $http service – it has methods with high-level behaviors – but the server URLs must be RESTful • REST: REpresentational State Transfer – works on the concept of “resource” • CRUD: Create, Read, Update and Delete read a collection of resources: GET /pizzas read a single resource: GET /pizzas/:id add a new resource: POST /pizzas update an existing resource: PUT /pizzas/:id delete an existing resource: DELETE /pizzas/:id 22/04/2016 AngularJS: an introduction 32
  • 33. The $resource Service • Requires the ngResource module to be installed • No callbacks needed! – e.g., $scope.pizzas = pizzaService.query(); • Available methods – get(), method: GET, single resource – query(), method: GET, is array (collection) – save(), method: POST – remove(), method: DELETE, – delete(), method: DELETE 22/04/2016 AngularJS: an introduction 33
  • 34. Custom Directives • Application specific – replace HTML tags with “functional” tags you define e.g., DatePicker, Accordion, ... • Naming • Camel case naming (ngRepeat) – automatically mapped to ng-repeat, data-ng- repeat in the templates e.g., <div ng-repeat></div> 22/04/2016 AngularJS: an introduction 34
  • 35. Custom Directives • A directive returns an “object” (directive definition) with several properties – details: https://docs.angularjs.org/api/ng/service/$compile 22/04/2016 AngularJS: an introduction 35 var sonet = angular.module('sonetExample', []); sonet.directive('helloHeader', function() { return { restrict: 'E', template: '<h2>Hello World!</h2>' }; }); JS
  • 36. Custom Directives 22/04/2016 AngularJS: an introduction 36 var sonet = angular.module('sonetExample', []); sonet.directive('helloHeader', function() { return { restrict: 'E', template: '<h2>Hello World!</h2>' }; }); JS Restricts the directive to a specific HTML "item". If omitted, the defaults (Elements and Attributes) are used.
  • 37. Custom Directives 22/04/2016 AngularJS: an introduction 37 var sonet = angular.module('sonetExample', []); sonet.directive('helloHeader', function() { return { restrict: 'E', template: '<h2>Hello World!</h2>' }; }); JS replace or wrap the contents of an element with this template
  • 38. Compile and Link • Named after the two phases Angular uses to create the live view for your application • Compile – looks for all the directives and transforms the DOM accordingly, then calls the compile function (if it exists) • Link – makes the view dynamic via directive link functions – the link functions typically create listeners on the DOM or the model; these listeners keep the view and the model in sync at all times – scopes are attached to the compiled link functions, and the directive becomes live through data binding 22/04/2016 AngularJS: an introduction 38
  • 39. Link Function: Example 22/04/2016 AngularJS: an introduction 39 var sonet = angular.module('sonetExample', []); sonet.directive('backButton', ['$window', function ($window) { return { restrict: 'A', link: function (scope, elem, attrs) { elem.bind('click', function () { $window.history.back(); }); } }; }]) JS
  • 40. BEST PRACTICES Other best practices in AngularJS 22/04/2016 AngularJS: an introduction 40
  • 41. A dot in the model "There should always be a dot in your model" Parent scope: $scope.name = "Anon" Child scope: <input type="text" ng-model="name"> The application will display "Anon" initially, but once the user change the value a name will be created on the child scope and the binding will read and write that value. The parent's name will remain "Anon". This can cause problems in large applications. To avoid them: <input type="text" ng-model="person.name"> 22/04/2016 AngularJS: an introduction 41
  • 42. camelCase vs dash-case You can use variable named like my-variable myVariable • The latter can cause problems in HTML – it is case-insensitive • Angular solution: use either, it will map them to the same thing Use dash-case in HTML and camelCase in JavaScript 22/04/2016 AngularJS: an introduction 42
  • 43. BACKGROUND Concepts behind AngularJS. Briefly. 22/04/2016 AngularJS: an introduction 43
  • 44. Model-View-Controller Pattern • Model – manage the application data – e.g., Javascript objects representing pizza names, pictures, comments, etc. • View – what the web page looks like – e.g., HTML/CSS for viewing pizzas, view pizza photos, etc. • Controller – fetch models and control views, handle user interactions • e.g., Javascript code for DOM event handlers, server communication, etc. 22/04/2016 AngularJS: an introduction 44
  • 45. View Generation (frontend) • HTML/CSS is generated in the frontend • Templates are commonly used • Basic idea – write a HTML document containing parts of the page that do not change – add some code that generate the parts computed for each page – the template is expanded by executing the code and substituting the result into the document • Angular has a rich templating language 22/04/2016 AngularJS: an introduction 45
  • 46. Models in Angular • Angular does not specify model data – i.e., as Javascript objects • It provides support for fetching data from a web server – support for REST APIs – JSON is frequently used 22/04/2016 AngularJS: an introduction 46
  • 47. Single Page Applications • Web applications in which the appropriate resource is dynamically loaded and added to the page when necessary • Instead of changing the page, a view inside the page is changed – “everything is in a single web page” – exploits the templating approach • The entire page does not reload – it uses AJAX 22/04/2016 AngularJS: an introduction 47
  • 48. Single Page Applications Problems: 1. mimic static addresses (http://mysite.com/...) and manage browser history 2. mix HTML and JavaScript 3. handle AJAX callbacks Solutions: [managed by Angular and similar frameworks] 1. routing (http://mysite.com/#...) 2. templating 3. server backend + HTML5 functionalities 22/04/2016 AngularJS: an introduction 48
  • 49. References • AngularJS official guide – https://docs.angularjs.org/guide • AngularJS API documentation – https://docs.angularjs.org/api • AngularJS in 60 minutes [video] – https://www.youtube.com/watch?v=i9MHigUZKEM • Learn Angular in your browser – http://angular.codeschool.com/ 22/04/2016 AngularJS: an introduction 49
  • 50. Questions? 01QYAPD SOCIAL NETWORKING: TECHNOLOGIES AND APPLICATIONS Luigi De Russis luigi.derussis@polito.it
  • 51. License • This work is licensed under the Creative Commons “Attribution- NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License. • You are free: – to Share - to copy, distribute and transmit the work – to Remix - to adapt the work • Under the following conditions: – Attribution - You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). – Noncommercial - You may not use this work for commercial purposes. – Share Alike - If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. • To view a copy of this license, visit http://creativecommons.org/license/by-nc-sa/3.0/ 22/04/2016 AngularJS: an introduction 51