SlideShare a Scribd company logo
AngularJS
Pasi Manninen
JAMK University of Applied Sciences
Slide version Mar 6th, 2014
AngularJS
• Google's open-source framework for developing Web
applications
• Target is creating single-page web applications with
MVC capability
• 100% JavaScript and 100% client side
• Updates very often (about 4 times a month, 1st version
June 2012)
• Supports modern desktop and mobile browsers
• Very good documentation and tutorials
– http://angularjs.org
– http://www.youtube.com/user/angularjs
AngularJS, Pasi Manninen. 2
Remember read: http://docs.angularjs.org/guide/introduction
Angular Consepts
AngularJS, Pasi Manninen. 3
http://docs.angularjs.org/guide/concepts
Angular Directives (notable)
AngularJS, Pasi Manninen. 4
http://en.wikipedia.org/wiki/AngularJS
Key Features
• Data Binding
– two-way data-binding automatically handles values between
model and view
– http://jsfiddle.net/HweGq/
• Scope
– object that refers to the model
– glues the controller and the view
• Controllers
– JavaScript functions which are bound to a particular scope
– http://jsfiddle.net/HweGq/1/ (scope variable problem)
– http://jsfiddle.net/HweGq/2/ (corrected with controller)
– http://jsfiddle.net/HweGq/3/ (controller inside module)
– http://jsfiddle.net/HweGq/4/ (controller with methods)
AngularJS, Pasi Manninen. 5
Key Features
• Services
– angular comes with several built-in services (for
example $http to make a XMLHttpRequests)
– singleton objects which are instantiated only once
in app
– can be made own services with factory
– http://jsfiddle.net/HweGq/5/ (share data between
controllers)
AngularJS, Pasi Manninen. 6
Example: Services
• Use service to load JSON from the server
• http://ptm.fi/angular/MovieExample/
AngularJS, Pasi Manninen. 7
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>AngularJS - movie service</title>
<script src="angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="MovieController">
<h2>{{movieName}}</h2>
<video controls ng-src="{{movieUrl}}"></video>
</div>
</body>
</html>
// app.js
var myApp = angular.module('myApp', []);
myApp.factory('MovieService', function ($http) {
var data = {};
data.url = "http://ptm.fi/angular/MovieExample/movie.php";
data.getMovie = function() {
return $http.get(data.url);
}
return data;
});
myApp.controller('MovieController', function($scope,$sce,MovieService) {
MovieService.getMovie().success(function (response) {
$scope.movieName = response.name;
var movieUrl = response.url;
$scope.movieUrl = $sce.trustAsResourceUrl(movieUrl);
});
});
<?php // movie.php
echo '{"url":"http://fin.clip-1.filmtrailer.com/11195_41463_a_6.mp4","name":"21 tapaa pilata avioliitto"}';
?>
Key Features
• Filters
– selects a subset of items from array and returns a new array
– http://jsfiddle.net/xLrZF/
• Directives
– directives are markers on a DOM element (like elements, attributes,
css, …)
– angular has own build-in directives (ngBind, ngModel, …)
– can be made own ones
– http://jsfiddle.net/WAN4H/ (as element)
– http://jsfiddle.net/WAN4H/1/ (as attribute)
– http://jsfiddle.net/WAN4H/2/ (as class attribute)
– http://jsfiddle.net/WAN4H/3/ (as comment)
– http://jsfiddle.net/WAN4H/4/ (with events)
– http://jsfiddle.net/WAN4H/5/ (with events to controller)
– try nice demos at http://docs.angularjs.org/guide/directive
AngularJS, Pasi Manninen. 8
’E’ – Element
’A’ – Attribute (default)
’C’ – Class
’M’ – Comment
Key Features
• Templates
– rendered view with information from the controller
and model
– can be one file (like index.html) or multiple views in
one page using “partials”
– partials are included to main page using $route
service with ngView directive
– http://ptm.fi/angular/TemplatesExample/ (no
templates used)
– http://ptm.fi/angular/TemplatesExample/index2.html
(templateUrl used in app2.js)
AngularJS, Pasi Manninen. 9
Key Features
• Routing (switch views)
– use ng-view directive that angular uses as a
container (to switch between views)
– links to controller and template with config
function and $routeProvider
– http://ptm.fi/angular/RoutingExample/
(one template)
AngularJS, Pasi Manninen. 10
Example: Routing (1/2)
• Use ng-view directive to show to different routing templates
• http://ptm.fi/angular/RoutingExample2/
• index.html and templates: app.html, user.html
AngularJS, Pasi Manninen. 11
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>AngularJS - routing example</title>
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<ng-view></ng-view>
</body>
</html> <div ng-controller="AppCtrl">
<table>
<tr><th>Firstname</th><th>Lastname</th></tr>
<tr ng-repeat="user in users" ng-click="clicked($index)">
<td>{{user.firstname}}</td>
<td>{{user.lastname}}</td>
</tr>
</table>
</div>
<div ng-controller="UserCtrl">
<h3>User Details</h3>
<p>
{{user.firstname}} {{user.lastname}}<br/>
<img ng-src="{{user.image}}"/><br/>
{{user.details}}
</p>
</div>
click name to change
template in ng-view
Example: Routing (2/2)
• Use ng-view directive to show to different routing templates
• http://ptm.fi/angular/RoutingExample2/
• app.js (routes, controllers and one service)
AngularJS, Pasi Manninen. 12
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider
.when("/", { templateUrl: 'app.html', controller: 'AppCtrl‘ })
.when('/users/:userId', { templateUrl: 'user.html', controller: 'UserCtrl‘ })
.otherwise({redirectTo: '/'});
});
myApp.controller("UserCtrl", function($scope,$routeParams,UsersService) {
$scope.user = UsersService.users[$routeParams.userId];
});
myApp.controller("AppCtrl", function($scope,$location,UsersService){
$scope.users = UsersService.users;
$scope.clicked = function(index) {
$location.path("/users/"+index);
}
});
myApp.factory('UsersService', function () {
var users =
[
{firstname:"Kirsi",lastname:"Kernel",details:"Kirsi is..",image:"employee01.png"},
{firstname:"Matti",lastname:"Husso",details:"Matti is..",image:"employee02.png"}
];
return {users:users};
});
click name to change
template in ng-view
Hands-On: Users Demo - client
• Show all users, edit or delete from database
• Controllers:
– UsersCtrl
– AddUserCtrl
– EditUserCtrl
• Services:
– UsersService
• Routes
– /
– /addUser
– /edit/:userId
• Views
– users.html
– adduser.html
– edituser.html
• http://ptm.fi/angular/UsersDemo/
AngularJS, Pasi Manninen. 13
Hands-On: User Demo - database
• Use MySQL Workbench and create table
– table name is Users
– id primary key not null auto increment
– username, firstname and lastname as varchar
AngularJS, Pasi Manninen. 14
Hands-On: User Demo - server
• Use PHP
– config.php
– adduser.php
– deleteuser.php
– edituser.php
– getusers.php
AngularJS, Pasi Manninen. 15
INSERT INTO Users (username,firstname,lastname) VALUES….
DELETE FROM Users WHERE…..
UPDATE Users SET username=…..
SELECT * FROM Users…..
Exercise: Android devices
• Work through the tutorial to see how Angular
makes browsers smarter without the use of
extensions or plug-ins
• The tutorial guides you
through the entire process
of building a simple
application
• http://docs.angularjs.org/tutorial
AngularJS, Pasi Manninen. 16
Exercise: Finnkino
• Create an AngularJS based single page web
application which loads and shows the movie
data from the Finnkino web service
• A few keywords:
– bootstrap css
– own templates
– controls and services
– PHP to cache data
AngularJS, Pasi Manninen. 17
Tutorial is not included to this power point material.

More Related Content

What's hot

The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014
Matt Raible
 
MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)
Chris Clarke
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
Caldera Labs
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Narek Mamikonyan
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
Visual Engineering
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
Dan Wahlin
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
Loc Nguyen
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalCampDN
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
Den Odell
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
Luigi De Russis
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
Dan Wahlin
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
Boyan Mihaylov
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
Visual Engineering
 
Introducing AngularJS
Introducing AngularJSIntroducing AngularJS
Introducing AngularJS
Loc Nguyen
 

What's hot (20)

The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014
 
MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
Requirejs
RequirejsRequirejs
Requirejs
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Introducing AngularJS
Introducing AngularJSIntroducing AngularJS
Introducing AngularJS
 

Viewers also liked

PHP 2
PHP 2PHP 2
PHP 2
Richa Goel
 
Php
PhpPhp
Wordpress Intro
Wordpress IntroWordpress Intro
Wordpress Intro
Richa Goel
 
Responsive web design
Responsive web designResponsive web design
Responsive web designRicha Goel
 
Adobe AIR Programming to Desktop and Mobile
Adobe AIR Programming to Desktop and MobileAdobe AIR Programming to Desktop and Mobile
Adobe AIR Programming to Desktop and Mobile
Pasi Manninen
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and Archives
Ned Potter
 

Viewers also liked (6)

PHP 2
PHP 2PHP 2
PHP 2
 
Php
PhpPhp
Php
 
Wordpress Intro
Wordpress IntroWordpress Intro
Wordpress Intro
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Adobe AIR Programming to Desktop and Mobile
Adobe AIR Programming to Desktop and MobileAdobe AIR Programming to Desktop and Mobile
Adobe AIR Programming to Desktop and Mobile
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and Archives
 

Similar to AngularJS

Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
Tamer Solieman
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
Johannes Weber
 
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
Learnimtactics
 
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
Stéphane Bégaudeau
 
Angular js
Angular jsAngular js
Angular js
Hritesh Saha
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
EPAM Systems
 
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
MongoDB
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
Rolands Krumbergs
 
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
Suresh Patidar
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
jagriti srivastava
 
AngularJS
AngularJSAngularJS
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
murtazahaveliwala
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
Filip Janevski
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
Gaurav Agrawal
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
Oswald Campesato
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
Jasper Moelker
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Jalal Mostafa
 

Similar to AngularJS (20)

Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
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
 
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
 
Angular js
Angular jsAngular js
Angular js
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
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 workshop
Angular js workshopAngular js workshop
Angular js workshop
 
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
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS
AngularJSAngularJS
AngularJS
 
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
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...
 

Recently uploaded

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

AngularJS

  • 1. AngularJS Pasi Manninen JAMK University of Applied Sciences Slide version Mar 6th, 2014
  • 2. AngularJS • Google's open-source framework for developing Web applications • Target is creating single-page web applications with MVC capability • 100% JavaScript and 100% client side • Updates very often (about 4 times a month, 1st version June 2012) • Supports modern desktop and mobile browsers • Very good documentation and tutorials – http://angularjs.org – http://www.youtube.com/user/angularjs AngularJS, Pasi Manninen. 2 Remember read: http://docs.angularjs.org/guide/introduction
  • 3. Angular Consepts AngularJS, Pasi Manninen. 3 http://docs.angularjs.org/guide/concepts
  • 4. Angular Directives (notable) AngularJS, Pasi Manninen. 4 http://en.wikipedia.org/wiki/AngularJS
  • 5. Key Features • Data Binding – two-way data-binding automatically handles values between model and view – http://jsfiddle.net/HweGq/ • Scope – object that refers to the model – glues the controller and the view • Controllers – JavaScript functions which are bound to a particular scope – http://jsfiddle.net/HweGq/1/ (scope variable problem) – http://jsfiddle.net/HweGq/2/ (corrected with controller) – http://jsfiddle.net/HweGq/3/ (controller inside module) – http://jsfiddle.net/HweGq/4/ (controller with methods) AngularJS, Pasi Manninen. 5
  • 6. Key Features • Services – angular comes with several built-in services (for example $http to make a XMLHttpRequests) – singleton objects which are instantiated only once in app – can be made own services with factory – http://jsfiddle.net/HweGq/5/ (share data between controllers) AngularJS, Pasi Manninen. 6
  • 7. Example: Services • Use service to load JSON from the server • http://ptm.fi/angular/MovieExample/ AngularJS, Pasi Manninen. 7 <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>AngularJS - movie service</title> <script src="angular.min.js"></script> <script src="app.js"></script> </head> <body> <div ng-controller="MovieController"> <h2>{{movieName}}</h2> <video controls ng-src="{{movieUrl}}"></video> </div> </body> </html> // app.js var myApp = angular.module('myApp', []); myApp.factory('MovieService', function ($http) { var data = {}; data.url = "http://ptm.fi/angular/MovieExample/movie.php"; data.getMovie = function() { return $http.get(data.url); } return data; }); myApp.controller('MovieController', function($scope,$sce,MovieService) { MovieService.getMovie().success(function (response) { $scope.movieName = response.name; var movieUrl = response.url; $scope.movieUrl = $sce.trustAsResourceUrl(movieUrl); }); }); <?php // movie.php echo '{"url":"http://fin.clip-1.filmtrailer.com/11195_41463_a_6.mp4","name":"21 tapaa pilata avioliitto"}'; ?>
  • 8. Key Features • Filters – selects a subset of items from array and returns a new array – http://jsfiddle.net/xLrZF/ • Directives – directives are markers on a DOM element (like elements, attributes, css, …) – angular has own build-in directives (ngBind, ngModel, …) – can be made own ones – http://jsfiddle.net/WAN4H/ (as element) – http://jsfiddle.net/WAN4H/1/ (as attribute) – http://jsfiddle.net/WAN4H/2/ (as class attribute) – http://jsfiddle.net/WAN4H/3/ (as comment) – http://jsfiddle.net/WAN4H/4/ (with events) – http://jsfiddle.net/WAN4H/5/ (with events to controller) – try nice demos at http://docs.angularjs.org/guide/directive AngularJS, Pasi Manninen. 8 ’E’ – Element ’A’ – Attribute (default) ’C’ – Class ’M’ – Comment
  • 9. Key Features • Templates – rendered view with information from the controller and model – can be one file (like index.html) or multiple views in one page using “partials” – partials are included to main page using $route service with ngView directive – http://ptm.fi/angular/TemplatesExample/ (no templates used) – http://ptm.fi/angular/TemplatesExample/index2.html (templateUrl used in app2.js) AngularJS, Pasi Manninen. 9
  • 10. Key Features • Routing (switch views) – use ng-view directive that angular uses as a container (to switch between views) – links to controller and template with config function and $routeProvider – http://ptm.fi/angular/RoutingExample/ (one template) AngularJS, Pasi Manninen. 10
  • 11. Example: Routing (1/2) • Use ng-view directive to show to different routing templates • http://ptm.fi/angular/RoutingExample2/ • index.html and templates: app.html, user.html AngularJS, Pasi Manninen. 11 <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>AngularJS - routing example</title> <script src="angular.min.js"></script> <script src="angular-route.min.js"></script> <script src="app.js"></script> </head> <body> <ng-view></ng-view> </body> </html> <div ng-controller="AppCtrl"> <table> <tr><th>Firstname</th><th>Lastname</th></tr> <tr ng-repeat="user in users" ng-click="clicked($index)"> <td>{{user.firstname}}</td> <td>{{user.lastname}}</td> </tr> </table> </div> <div ng-controller="UserCtrl"> <h3>User Details</h3> <p> {{user.firstname}} {{user.lastname}}<br/> <img ng-src="{{user.image}}"/><br/> {{user.details}} </p> </div> click name to change template in ng-view
  • 12. Example: Routing (2/2) • Use ng-view directive to show to different routing templates • http://ptm.fi/angular/RoutingExample2/ • app.js (routes, controllers and one service) AngularJS, Pasi Manninen. 12 var myApp = angular.module('myApp', ['ngRoute']); myApp.config(function($routeProvider){ $routeProvider .when("/", { templateUrl: 'app.html', controller: 'AppCtrl‘ }) .when('/users/:userId', { templateUrl: 'user.html', controller: 'UserCtrl‘ }) .otherwise({redirectTo: '/'}); }); myApp.controller("UserCtrl", function($scope,$routeParams,UsersService) { $scope.user = UsersService.users[$routeParams.userId]; }); myApp.controller("AppCtrl", function($scope,$location,UsersService){ $scope.users = UsersService.users; $scope.clicked = function(index) { $location.path("/users/"+index); } }); myApp.factory('UsersService', function () { var users = [ {firstname:"Kirsi",lastname:"Kernel",details:"Kirsi is..",image:"employee01.png"}, {firstname:"Matti",lastname:"Husso",details:"Matti is..",image:"employee02.png"} ]; return {users:users}; }); click name to change template in ng-view
  • 13. Hands-On: Users Demo - client • Show all users, edit or delete from database • Controllers: – UsersCtrl – AddUserCtrl – EditUserCtrl • Services: – UsersService • Routes – / – /addUser – /edit/:userId • Views – users.html – adduser.html – edituser.html • http://ptm.fi/angular/UsersDemo/ AngularJS, Pasi Manninen. 13
  • 14. Hands-On: User Demo - database • Use MySQL Workbench and create table – table name is Users – id primary key not null auto increment – username, firstname and lastname as varchar AngularJS, Pasi Manninen. 14
  • 15. Hands-On: User Demo - server • Use PHP – config.php – adduser.php – deleteuser.php – edituser.php – getusers.php AngularJS, Pasi Manninen. 15 INSERT INTO Users (username,firstname,lastname) VALUES…. DELETE FROM Users WHERE….. UPDATE Users SET username=….. SELECT * FROM Users…..
  • 16. Exercise: Android devices • Work through the tutorial to see how Angular makes browsers smarter without the use of extensions or plug-ins • The tutorial guides you through the entire process of building a simple application • http://docs.angularjs.org/tutorial AngularJS, Pasi Manninen. 16
  • 17. Exercise: Finnkino • Create an AngularJS based single page web application which loads and shows the movie data from the Finnkino web service • A few keywords: – bootstrap css – own templates – controls and services – PHP to cache data AngularJS, Pasi Manninen. 17 Tutorial is not included to this power point material.