angularJs Workshop

Ran Wahle
Ran WahleJavascript developer at Tikal - Fullstack as a Service em Tikal - Fullstack as a Service
© Copyright SELA Software & Education Labs, Ltd. | 14-18 Baruch Hirsch St., Bnei Brak, 51202 Israel | www.selagroup.com
SELA DEVELOPER PRACTICE
May 31st – June 4th, 2015
Ran Wahle
AngularJS – from 0 to 60
Agenda
Introduction
Modules and dependency injection
Data binding, controllers and scopes
Services
Filters
Directives
Form validation
Routing
The Modern Web
From web pages to web applications
More and more logic is pushed to the client
The Problem
As we add more and more JavaScript, our
application is getting:
Introduction to
AngularJS
What Is AngularJS?
An MV* framework for developing CRUD style web applications
Developed by Google
Works on all modern web browsers
Open source (MIT license)
No external dependencies
Demo
The Simplest Angular Application
Angular Building Blocks
Module
Module
Module
Scope Controller ServiceTemplate
Filter Directive
Two-Way
Binding
Dependency
Injection
Routing
<!doctype html>
<html data-ng-app>
<head>
</head>
<body>
<input type="text" data-ng-model="name" />
{{name}}
</body>
</html>
Your first AngularJS page
Module
Divide application into small pieces
Can contain controllers, services, directives, etc.
Can depend on other modules
Other modules can depend on it
//Creating a module
angular.module('yourModuleName', [ /*…dependencies…*/ ]);
//Accessing a module
angular.module('yourModuleName'); //Note: no dependencies array
Creating a module
Dependency Injection
Each angular application has an $injector service
Components are injected by the $injector
There are several options for using dependency
injection
One option removes the responsibility of locating the
dependency from the component. The dependency is simply
handed to the component.
In Angular each application has an injector that is responsible
for construction and lookup of dependencies
function SomeClass(greeter) {
this.greeter = greeter;
}
SomeClass.prototype.doSomething = function(name) {
this.greeter.greet(name);
}
Dependency Injection cont.
Creating a component
angular.module('yourModuleName').service('serviceName', function() {
//service’s code
});
Creating an Angular component
Consuming the component
angular.module('yourModuleName')
.controller('controllerName', ['serviceName', function(serviceName) {
//controller’s code
});
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Data binding
Controllers, scopes and views
AngularJS supports MV *- patterns
Views
HTML
templates
Controllers
JavaScript
functions
Data Model
$scope
HTML templates
An HTML element with Angular-related attributes
Declarative
Contains Angular-specific elements and attributes
Contains expressions evaluated against scope
properties
<html>
<head>
</head>
<body data-ng-app="myAppName">
<div data-ng-controller="myController">
<input data-ng-model="name" />
<button data-ng-click="greet()">Greet</button>
</div>
</body>
</html>
HTML template
Controller
A JavaScript constructor function
Contains view related logic
Can get and set data on the $scope
Shouldn’t have any DOM related functionality
Sets up the $scope initial state
Associated with a template via the ng-controller directive
angular.module('myAppName')
.controller('myController', ['$scope', function($scope) {
var greet = function() {
alert('Hello ' + $scope.name);
};
$scope.greet = greet;
}]);
Controller
$scope
The glue between the HTML template
and the controller
Hierarchical in the same way as HTML
Hierarchy implemented using
JavaScript prototypes
The root scope is represented by the
$rootScope service
Demo
Controllers, views and $scope
Services
Reusable singleton objects
Can be injected into controllers, filters,
directives and other services
Created only when needed
There are many built-in services in
AngularJS
angular.module('myApp')
.service('myService', [/*…dependencies…*/, function(/*…dependencies…*/) {
//service logic here
this.someMethod = function() {};
}]);
angular.module('myApp')
.controller('myController', ['myService', function(myService) {
myService.someMetho();
}]);
Creating and using a service
Built-in services
$rootScope
$timeout
$location
$interval
$log
$compile
$rootElement
$parse
$window
$cacheFactory $animate
Demo
Using a service
Ajax using $http
$http service is a built-in service in AngularJS
Used for communicating with the server
Wraps XMLHttpRequest
Automatically serializes/deserializes JSON
Supports request and response
transformation
Supports request and response interception
$http.get('url')
.success(function(response) {
//handle the server's response
})
.error(function(errorResponse) {
//handle the server's error response
});
$http.post('url', requestBody);
$http.put('url', requestBody);
$http.delete('url', requestBody);
Using $http
$http({
url: 'url',
method: 'get', //or 'put', 'post', 'delete'
params: {…}, //for get requests
data: {…}, //for put or post requests
}).success(…).error(…).finally(…);
Using $http (Cont)
The $resource Service
An abstraction on top of the $http service for interaction with
RESTful web services
Depends on the ngResource module and requires the inclusion
of the angular-resource.js script
Receives a parameterized URL, with optional default values
Returns an object with convenient methods (get, query, $save,
$delete, …)
Custom actions can be configured as well
Using the $resource service
angular.module('resourceDemo', ['ngResource'])
.controller('questionsCtrl', function($scope) {
var baseUrl = '/api/v1.0/questions/:id';
var Questions = $resource(baseUrl, {id: '@id'});
$scope.loadQuestions = function() {
$scope.questions = Questions.query();
};
$scope.removeQuestion = function(question) {
question.$remove();
};
});
Demo
Using built-in services
Filters
Formats the value of an expression for display to the user
{{ expression | filter }}
{{ 10 | currency }} will display 10$
May have arguments
{{ price | number:2 }}
Chainable
angular.module('myModule')
.filter('digitToText', function() {
var digitToText = [
'zero', 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine'
];
return function(digit) {
return digitToText[digit];
};
});
Create a custom filter
Demo
Using filters
The form directive
Aggregates the state of all its input elements
Sets CSS classes according to the state
The default form action is automatically ignored
Available to the scope as a property with the name of the form
Contained input elements are also available by their names, as sub-
properties of the form property
The form directive
Creates a formController
The formController aggregates the state of all form controls
The formController is available to the current scope by its name
To submit the form using Ajax, respond to ng-submit or ng-click
Built-in validation directives
Angular provides the following validation directives:
required – Checks that the field has a value
min – Checks that the field value is greater than the given value
max – Checks that the field value is lower than the given value
minlength – Checks that the field value is longer than the given value
maxlength – Checks that the field value is shorter than the given value
pattern – Checks that the field value matches the given regular
expression
All of the above directives set a validation error identified by
their name when the condition is not met
The ngModel directive
Provides a two way data binding between the input
element and the model
Provides automatic validation for common HTML5
input types (checkbox, email, number, text, url)
Tracks the control’s state
Sets CSS classes according to the state
Note the usage of the novalidate attribute to disable
the browser’s built-in validation
<form name="form" novalidate>
<div>
<input type="text" name="title" ng-model="question.title" required />
</div>
<div>
<textarea name="content" ng-model="question.content" required>
</textarea>
</div>
<button ng-click="addQuestion(question)”>
Submit
</button>
</form>
Using the form and ngModel directives
Demo
Using forms
Directives
Custom HTML elements, attributes, classes and
comments that are recognized by Angular
Essentially extend the existing HTML vocabulary
Creating new elements
Adding behavior to existing elements
Most of the things we’ve seen so far are built-in
directives (ng-app, ng-controller, ng-repeat, ng-
model, required, …)
Creating custom directives
Directives are registered on modules, with the
module.directive function, which takes the
directive name and a factory function
The factory function should return a directive
definition object (discussed in the following
slides)
It’s a best practice to prefix custom directives to
prevent collision with other 3rd party directives,
or a future standard
The following code demonstrates the definition
of a new directive, named myDirective
Note that this is a only a skeleton with an
empty directive definition object. We’ll fill this
object with properties in the following slides.
myModule.directive('myDirective', function() {
return {
};
});
Creating a custom directive
Create a custom directive
The object retuned can have the
following properties:
• link: a function that is called during the linking phase
• template: an HTML template for the directive
• templateUrl: a rooted path to an HTML template file
• require: specifies a dependency on another directive
• transclude: determines whether child elements should
be included in the template
• controller: used to share behavior and communicate
with other directives
Demo
Custom directives
Routing in Single Page Applications
Unlike traditional web sites, in SPAs, the
responsibility for rendering the view is on the client
side
We do, however, want to give the user the same
features they are used to, such as:
The browser’s navigation buttons
The address bar for navigation
The ability to bookmark specific pages
How can we change the address bar without causing
the browser to issue a new request?
The $location service
An abstraction on top of the window.location
object
Synchronized with the browser address bar and
allows to watch or manipulate the URL
Seamless integration with the HTML5 History API.
Links are automatically rewritten to reflect the
supported mode.
<a href="/page1?id=123">link</a>
/index.html#/page1?id=123
/page1?id=123
The ui.router module
Angular comes with a built-in router named ngRoute
But most projects use the 3rd party AngularUI Router
The AngularUI Router is packaged in its own module,
named ui.router
To use the router, perform the following steps:
Install and reference the angular-ui-router.js script in the HTML
Add the ui.router module as a dependency to your module
Routes are registered in the module’s config
function, by calling the $stateProvider.state
method with a state name and a route object
A default route can be registered with the
$routeProvider.otherwise method
The contents of the route object are discussed in
the following slides
myModule.config(function($stateProvider) {
$stateProvider("page1", {url: '/page1', …})
.state("page2", {…})
.state("page3", {…})
});
Route registration
The 3rd party uiView directive marks the place in
which the new route’s template should be
rendered
Can be used as an element, or as an attribute on
any element
<body ng-app="myModule">
<div>
<ul>
<li><a ui-sref="page1">Page 1</a></li>
<li><a ui-sref="page2">Page 2</a></li>
</ul>
</div>
<div ui-view />
</body>
The uiView directive
Demo
Routing
Modules and dependency injection
Data binding, controllers and scopes
Services
Filters
Form validation
Directives
Routing
Email: ranw@sela.co.il
Summary
Questions
1 de 54

Recomendados

AngularJs Workshop SDP December 28th 2014 por
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
510 visualizações54 slides
Asp.net mvc training por
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc trainingicubesystem
603 visualizações67 slides
Angular js por
Angular jsAngular js
Angular jsSilver Touch Technologies Ltd
54 visualizações24 slides
Asp.NET MVC por
Asp.NET MVCAsp.NET MVC
Asp.NET MVCvrluckyin
436 visualizações69 slides
Angular workshop - Full Development Guide por
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
342 visualizações110 slides
Intoduction to Angularjs por
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
267 visualizações25 slides

Mais conteúdo relacionado

Mais procurados

AngularJs presentation por
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
1.4K visualizações60 slides
Angular Presentation por
Angular PresentationAngular Presentation
Angular PresentationAdam Moore
167 visualizações24 slides
Front end development with Angular JS por
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
861 visualizações29 slides
Angular js 1.3 presentation for fed nov 2014 por
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
1.4K visualizações36 slides
Introduction to Angular JS por
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JSSanthosh Kumar Srinivasan
1.2K visualizações40 slides
AngularJs (1.x) Presentation por
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) PresentationRaghubir Singh
339 visualizações19 slides

Mais procurados(20)

AngularJs presentation por Phan Tuan
AngularJs presentation AngularJs presentation
AngularJs presentation
Phan Tuan1.4K visualizações
Angular Presentation por Adam Moore
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore167 visualizações
Front end development with Angular JS por Bipin
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
Bipin861 visualizações
Angular js 1.3 presentation for fed nov 2014 por Sarah Hudson
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson1.4K visualizações
AngularJs (1.x) Presentation por Raghubir Singh
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
Raghubir Singh339 visualizações
Angular js for Beginnners por Santosh Kumar Kar
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
Santosh Kumar Kar181 visualizações
Model View Presenter presentation por Michael Cameron
Model View Presenter presentationModel View Presenter presentation
Model View Presenter presentation
Michael Cameron2K visualizações
Angular2 and TypeScript por David Giard
Angular2 and TypeScriptAngular2 and TypeScript
Angular2 and TypeScript
David Giard1.4K visualizações
Dynamic Application Development by NodeJS ,AngularJS with OrientDB por Apaichon Punopas
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas7.2K visualizações
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin por Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Barry Gervin1.4K visualizações
Break the monolith with (B)VIPER Modules por Nicola Zaghini
Break the monolith with (B)VIPER ModulesBreak the monolith with (B)VIPER Modules
Break the monolith with (B)VIPER Modules
Nicola Zaghini1.4K visualizações
angularJS Practicle Explanation por Abhishek Sahu
angularJS Practicle ExplanationangularJS Practicle Explanation
angularJS Practicle Explanation
Abhishek Sahu1.5K visualizações
Code Camp 06 Model View Presenter Architecture por bitburner93
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
bitburner931.3K visualizações
Angular2 por kunalkumar376
Angular2Angular2
Angular2
kunalkumar37615 visualizações
VIPER Architecture por Ahmed Lotfy
VIPER ArchitectureVIPER Architecture
VIPER Architecture
Ahmed Lotfy906 visualizações
Angular js presentation at Datacom por David Xi Peng Yang
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang1.1K visualizações

Similar a angularJs Workshop

introduction to Angularjs basics por
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
961 visualizações31 slides
Angular Js Get Started - Complete Course por
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
3.1K visualizações146 slides
Introduction to single page application with angular js por
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular jsMindfire Solutions
2K visualizações25 slides
Angular js por
Angular jsAngular js
Angular jsBaldeep Sohal
444 visualizações46 slides
Understanding angular js por
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
5.4K visualizações53 slides
Angular js por
Angular jsAngular js
Angular jsBehind D Walls
2K visualizações34 slides

Similar a angularJs Workshop(20)

introduction to Angularjs basics por Ravindra K
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K961 visualizações
Angular Js Get Started - Complete Course por EPAM Systems
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
EPAM Systems3.1K visualizações
Introduction to single page application with angular js por Mindfire Solutions
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
Mindfire Solutions2K visualizações
Angular js por Baldeep Sohal
Angular jsAngular js
Angular js
Baldeep Sohal444 visualizações
Understanding angular js por Aayush Shrestha
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha5.4K visualizações
Angular js por Behind D Walls
Angular jsAngular js
Angular js
Behind D Walls2K visualizações
Leveling up with AngularJS por Austin Condiff
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJS
Austin Condiff275 visualizações
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS por murtazahaveliwala
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
murtazahaveliwala777 visualizações
AngularJS in 60ish Minutes por Dan Wahlin
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
Dan Wahlin16.5K visualizações
Angularjs Basics por Anuradha Bandara
Angularjs BasicsAngularjs Basics
Angularjs Basics
Anuradha Bandara1.4K visualizações
MVC Training Part 2 por Lee Englestone
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
Lee Englestone521 visualizações
Angular por LearningTech
AngularAngular
Angular
LearningTech600 visualizações
Angular por LearningTech
AngularAngular
Angular
LearningTech400 visualizações
AngularJS Workshop por Gianluca Cacace
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace868 visualizações
Introduction to Angularjs : kishan kumar por Appfinz Technologies
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
Appfinz Technologies 19 visualizações
Introduction to Angularjs por Manish Shekhawat
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat67.3K visualizações
Introduction to AngularJS por Yoann Gotthilf
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Yoann Gotthilf2.2K visualizações
AngularJs Crash Course por Keith Bloomfield
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield9.8K visualizações

Mais de Ran Wahle

Into React-DOM.pptx por
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptxRan Wahle
8 visualizações55 slides
Lets go to the background por
Lets go to the backgroundLets go to the background
Lets go to the backgroundRan Wahle
88 visualizações21 slides
Permissions api por
Permissions apiPermissions api
Permissions apiRan Wahle
220 visualizações17 slides
Lets go vanilla por
Lets go vanillaLets go vanilla
Lets go vanillaRan Wahle
86 visualizações22 slides
Custom elements por
Custom elements Custom elements
Custom elements Ran Wahle
84 visualizações16 slides
Web workers por
Web workers Web workers
Web workers Ran Wahle
134 visualizações12 slides

Mais de Ran Wahle(20)

Into React-DOM.pptx por Ran Wahle
Into React-DOM.pptxInto React-DOM.pptx
Into React-DOM.pptx
Ran Wahle8 visualizações
Lets go to the background por Ran Wahle
Lets go to the backgroundLets go to the background
Lets go to the background
Ran Wahle88 visualizações
Permissions api por Ran Wahle
Permissions apiPermissions api
Permissions api
Ran Wahle220 visualizações
Lets go vanilla por Ran Wahle
Lets go vanillaLets go vanilla
Lets go vanilla
Ran Wahle86 visualizações
Custom elements por Ran Wahle
Custom elements Custom elements
Custom elements
Ran Wahle84 visualizações
Web workers por Ran Wahle
Web workers Web workers
Web workers
Ran Wahle134 visualizações
Using legacy code with micro frontends por Ran Wahle
Using legacy code with micro frontendsUsing legacy code with micro frontends
Using legacy code with micro frontends
Ran Wahle276 visualizações
Ngrx one-effect por Ran Wahle
Ngrx one-effectNgrx one-effect
Ngrx one-effect
Ran Wahle116 visualizações
Angular migration por Ran Wahle
Angular migrationAngular migration
Angular migration
Ran Wahle291 visualizações
Javascript async / await Frontend-IL por Ran Wahle
Javascript async / await Frontend-ILJavascript async / await Frontend-IL
Javascript async / await Frontend-IL
Ran Wahle184 visualizações
Boost js state management por Ran Wahle
Boost js state managementBoost js state management
Boost js state management
Ran Wahle242 visualizações
Angular 2.0 change detection por Ran Wahle
Angular 2.0 change detectionAngular 2.0 change detection
Angular 2.0 change detection
Ran Wahle608 visualizações
Code migration from Angular 1.x to Angular 2.0 por Ran Wahle
Code migration from Angular 1.x to Angular 2.0Code migration from Angular 1.x to Angular 2.0
Code migration from Angular 1.x to Angular 2.0
Ran Wahle413 visualizações
Async patterns in javascript por Ran Wahle
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
Ran Wahle420 visualizações
Angular js 2 por Ran Wahle
Angular js 2Angular js 2
Angular js 2
Ran Wahle962 visualizações
Asyncawait in typescript por Ran Wahle
Asyncawait in typescriptAsyncawait in typescript
Asyncawait in typescript
Ran Wahle413 visualizações
Angular%201%20to%20angular%202 por Ran Wahle
Angular%201%20to%20angular%202Angular%201%20to%20angular%202
Angular%201%20to%20angular%202
Ran Wahle799 visualizações
What’s new in angular 2 - From FrontEnd IL Meetup por Ran Wahle
What’s new in angular 2 - From FrontEnd IL MeetupWhat’s new in angular 2 - From FrontEnd IL Meetup
What’s new in angular 2 - From FrontEnd IL Meetup
Ran Wahle556 visualizações
What’s new in angular 2 por Ran Wahle
What’s new in angular 2What’s new in angular 2
What’s new in angular 2
Ran Wahle1.4K visualizações
Introduction to web compoents por Ran Wahle
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoents
Ran Wahle360 visualizações

Último

.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...Marc Müller
35 visualizações62 slides
Software evolution understanding: Automatic extraction of software identifier... por
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
7 visualizações33 slides
WebAssembly por
WebAssemblyWebAssembly
WebAssemblyJens Siebert
32 visualizações18 slides
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema por
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDeltares
12 visualizações13 slides
Neo4j y GenAI por
Neo4j y GenAI Neo4j y GenAI
Neo4j y GenAI Neo4j
35 visualizações41 slides
Applying Platform Engineering Thinking to Observability.pdf por
Applying Platform Engineering Thinking to Observability.pdfApplying Platform Engineering Thinking to Observability.pdf
Applying Platform Engineering Thinking to Observability.pdfNatan Yellin
12 visualizações16 slides

Último(20)

.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller35 visualizações
Software evolution understanding: Automatic extraction of software identifier... por Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Ra'Fat Al-Msie'deen7 visualizações
WebAssembly por Jens Siebert
WebAssemblyWebAssembly
WebAssembly
Jens Siebert32 visualizações
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema por Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares12 visualizações
Neo4j y GenAI por Neo4j
Neo4j y GenAI Neo4j y GenAI
Neo4j y GenAI
Neo4j35 visualizações
Applying Platform Engineering Thinking to Observability.pdf por Natan Yellin
Applying Platform Engineering Thinking to Observability.pdfApplying Platform Engineering Thinking to Observability.pdf
Applying Platform Engineering Thinking to Observability.pdf
Natan Yellin12 visualizações
Best Mics For Your Live Streaming por ontheflystream
Best Mics For Your Live StreamingBest Mics For Your Live Streaming
Best Mics For Your Live Streaming
ontheflystream6 visualizações
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... por Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 visualizações
Cycleops - Automate deployments on top of bare metal.pptx por Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Thanassis Parathyras30 visualizações
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida por Deltares
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
Deltares17 visualizações
Winter '24 Release Chat.pdf por melbourneauuser
Winter '24 Release Chat.pdfWinter '24 Release Chat.pdf
Winter '24 Release Chat.pdf
melbourneauuser9 visualizações
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... por Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller31 visualizações
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ... por marksimpsongw
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
marksimpsongw74 visualizações
HarshithAkkapelli_Presentation.pdf por harshithakkapelli
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdf
harshithakkapelli11 visualizações
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... por Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares10 visualizações
Software testing company in India.pptx por SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 visualizações
Unleash The Monkeys por Jacob Duijzer
Unleash The MonkeysUnleash The Monkeys
Unleash The Monkeys
Jacob Duijzer7 visualizações
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... por Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares16 visualizações
DevsRank por devsrank786
DevsRankDevsRank
DevsRank
devsrank78610 visualizações
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... por Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares7 visualizações

angularJs Workshop

  • 1. © Copyright SELA Software & Education Labs, Ltd. | 14-18 Baruch Hirsch St., Bnei Brak, 51202 Israel | www.selagroup.com SELA DEVELOPER PRACTICE May 31st – June 4th, 2015 Ran Wahle AngularJS – from 0 to 60
  • 2. Agenda Introduction Modules and dependency injection Data binding, controllers and scopes Services Filters Directives Form validation Routing
  • 3. The Modern Web From web pages to web applications More and more logic is pushed to the client
  • 4. The Problem As we add more and more JavaScript, our application is getting:
  • 6. What Is AngularJS? An MV* framework for developing CRUD style web applications Developed by Google Works on all modern web browsers Open source (MIT license) No external dependencies
  • 8. Angular Building Blocks Module Module Module Scope Controller ServiceTemplate Filter Directive Two-Way Binding Dependency Injection Routing
  • 9. <!doctype html> <html data-ng-app> <head> </head> <body> <input type="text" data-ng-model="name" /> {{name}} </body> </html> Your first AngularJS page
  • 10. Module Divide application into small pieces Can contain controllers, services, directives, etc. Can depend on other modules Other modules can depend on it
  • 11. //Creating a module angular.module('yourModuleName', [ /*…dependencies…*/ ]); //Accessing a module angular.module('yourModuleName'); //Note: no dependencies array Creating a module
  • 12. Dependency Injection Each angular application has an $injector service Components are injected by the $injector There are several options for using dependency injection
  • 13. One option removes the responsibility of locating the dependency from the component. The dependency is simply handed to the component. In Angular each application has an injector that is responsible for construction and lookup of dependencies function SomeClass(greeter) { this.greeter = greeter; } SomeClass.prototype.doSomething = function(name) { this.greeter.greet(name); } Dependency Injection cont.
  • 14. Creating a component angular.module('yourModuleName').service('serviceName', function() { //service’s code }); Creating an Angular component Consuming the component angular.module('yourModuleName') .controller('controllerName', ['serviceName', function(serviceName) { //controller’s code });
  • 15. © Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com Data binding Controllers, scopes and views
  • 16. AngularJS supports MV *- patterns Views HTML templates Controllers JavaScript functions Data Model $scope
  • 17. HTML templates An HTML element with Angular-related attributes Declarative Contains Angular-specific elements and attributes Contains expressions evaluated against scope properties
  • 18. <html> <head> </head> <body data-ng-app="myAppName"> <div data-ng-controller="myController"> <input data-ng-model="name" /> <button data-ng-click="greet()">Greet</button> </div> </body> </html> HTML template
  • 19. Controller A JavaScript constructor function Contains view related logic Can get and set data on the $scope Shouldn’t have any DOM related functionality Sets up the $scope initial state Associated with a template via the ng-controller directive
  • 20. angular.module('myAppName') .controller('myController', ['$scope', function($scope) { var greet = function() { alert('Hello ' + $scope.name); }; $scope.greet = greet; }]); Controller
  • 21. $scope The glue between the HTML template and the controller Hierarchical in the same way as HTML Hierarchy implemented using JavaScript prototypes The root scope is represented by the $rootScope service
  • 23. Services Reusable singleton objects Can be injected into controllers, filters, directives and other services Created only when needed There are many built-in services in AngularJS
  • 24. angular.module('myApp') .service('myService', [/*…dependencies…*/, function(/*…dependencies…*/) { //service logic here this.someMethod = function() {}; }]); angular.module('myApp') .controller('myController', ['myService', function(myService) { myService.someMetho(); }]); Creating and using a service
  • 27. Ajax using $http $http service is a built-in service in AngularJS Used for communicating with the server Wraps XMLHttpRequest Automatically serializes/deserializes JSON Supports request and response transformation Supports request and response interception
  • 28. $http.get('url') .success(function(response) { //handle the server's response }) .error(function(errorResponse) { //handle the server's error response }); $http.post('url', requestBody); $http.put('url', requestBody); $http.delete('url', requestBody); Using $http
  • 29. $http({ url: 'url', method: 'get', //or 'put', 'post', 'delete' params: {…}, //for get requests data: {…}, //for put or post requests }).success(…).error(…).finally(…); Using $http (Cont)
  • 30. The $resource Service An abstraction on top of the $http service for interaction with RESTful web services Depends on the ngResource module and requires the inclusion of the angular-resource.js script Receives a parameterized URL, with optional default values Returns an object with convenient methods (get, query, $save, $delete, …) Custom actions can be configured as well
  • 31. Using the $resource service angular.module('resourceDemo', ['ngResource']) .controller('questionsCtrl', function($scope) { var baseUrl = '/api/v1.0/questions/:id'; var Questions = $resource(baseUrl, {id: '@id'}); $scope.loadQuestions = function() { $scope.questions = Questions.query(); }; $scope.removeQuestion = function(question) { question.$remove(); }; });
  • 33. Filters Formats the value of an expression for display to the user {{ expression | filter }} {{ 10 | currency }} will display 10$ May have arguments {{ price | number:2 }} Chainable
  • 34. angular.module('myModule') .filter('digitToText', function() { var digitToText = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ]; return function(digit) { return digitToText[digit]; }; }); Create a custom filter
  • 36. The form directive Aggregates the state of all its input elements Sets CSS classes according to the state The default form action is automatically ignored Available to the scope as a property with the name of the form Contained input elements are also available by their names, as sub- properties of the form property
  • 37. The form directive Creates a formController The formController aggregates the state of all form controls The formController is available to the current scope by its name To submit the form using Ajax, respond to ng-submit or ng-click
  • 38. Built-in validation directives Angular provides the following validation directives: required – Checks that the field has a value min – Checks that the field value is greater than the given value max – Checks that the field value is lower than the given value minlength – Checks that the field value is longer than the given value maxlength – Checks that the field value is shorter than the given value pattern – Checks that the field value matches the given regular expression All of the above directives set a validation error identified by their name when the condition is not met
  • 39. The ngModel directive Provides a two way data binding between the input element and the model Provides automatic validation for common HTML5 input types (checkbox, email, number, text, url) Tracks the control’s state Sets CSS classes according to the state
  • 40. Note the usage of the novalidate attribute to disable the browser’s built-in validation <form name="form" novalidate> <div> <input type="text" name="title" ng-model="question.title" required /> </div> <div> <textarea name="content" ng-model="question.content" required> </textarea> </div> <button ng-click="addQuestion(question)”> Submit </button> </form> Using the form and ngModel directives
  • 42. Directives Custom HTML elements, attributes, classes and comments that are recognized by Angular Essentially extend the existing HTML vocabulary Creating new elements Adding behavior to existing elements Most of the things we’ve seen so far are built-in directives (ng-app, ng-controller, ng-repeat, ng- model, required, …)
  • 43. Creating custom directives Directives are registered on modules, with the module.directive function, which takes the directive name and a factory function The factory function should return a directive definition object (discussed in the following slides) It’s a best practice to prefix custom directives to prevent collision with other 3rd party directives, or a future standard
  • 44. The following code demonstrates the definition of a new directive, named myDirective Note that this is a only a skeleton with an empty directive definition object. We’ll fill this object with properties in the following slides. myModule.directive('myDirective', function() { return { }; }); Creating a custom directive
  • 45. Create a custom directive The object retuned can have the following properties: • link: a function that is called during the linking phase • template: an HTML template for the directive • templateUrl: a rooted path to an HTML template file • require: specifies a dependency on another directive • transclude: determines whether child elements should be included in the template • controller: used to share behavior and communicate with other directives
  • 47. Routing in Single Page Applications Unlike traditional web sites, in SPAs, the responsibility for rendering the view is on the client side We do, however, want to give the user the same features they are used to, such as: The browser’s navigation buttons The address bar for navigation The ability to bookmark specific pages How can we change the address bar without causing the browser to issue a new request?
  • 48. The $location service An abstraction on top of the window.location object Synchronized with the browser address bar and allows to watch or manipulate the URL Seamless integration with the HTML5 History API. Links are automatically rewritten to reflect the supported mode. <a href="/page1?id=123">link</a> /index.html#/page1?id=123 /page1?id=123
  • 49. The ui.router module Angular comes with a built-in router named ngRoute But most projects use the 3rd party AngularUI Router The AngularUI Router is packaged in its own module, named ui.router To use the router, perform the following steps: Install and reference the angular-ui-router.js script in the HTML Add the ui.router module as a dependency to your module
  • 50. Routes are registered in the module’s config function, by calling the $stateProvider.state method with a state name and a route object A default route can be registered with the $routeProvider.otherwise method The contents of the route object are discussed in the following slides myModule.config(function($stateProvider) { $stateProvider("page1", {url: '/page1', …}) .state("page2", {…}) .state("page3", {…}) }); Route registration
  • 51. The 3rd party uiView directive marks the place in which the new route’s template should be rendered Can be used as an element, or as an attribute on any element <body ng-app="myModule"> <div> <ul> <li><a ui-sref="page1">Page 1</a></li> <li><a ui-sref="page2">Page 2</a></li> </ul> </div> <div ui-view /> </body> The uiView directive
  • 53. Modules and dependency injection Data binding, controllers and scopes Services Filters Form validation Directives Routing Email: ranw@sela.co.il Summary