SlideShare a Scribd company logo
1 of 40
Introduction to Angular
What is Angular ?
 Angular is a platform that
helps you create advanced
web applications in HTML
using Typescript (Dart or
ES5).
 It helps you to structure
your code, separate your
concerns and remove trivial
code.
Angular Modularity
Angular applications are based on
Modules.
Angular Modules helps organizing the
application into cohesive blocks of
functionality.
A module is implemented as a class.
Declares which components, services
etc that belongs together.
Angular AppModule
Every Angular applications
have at least one module - the
RootModule by convention
named AppModule.
Larger Angular applications
will have feature and route
modules as well.
Angular AppModule
Angular Architecture
Angular Architecture
The architecture diagram identifies the eight main
building blocks of an Angular application:
 Modules
 Components
 Templates
 Metadata
 Data binding
 Directives
 Services
 Dependency injection
Angular
Components
 A component controls a piece of the
screen called a view.
 A component's application logic—what it
does to support the view—is defined in a
class.
The class interacts with the view
through an API of properties and
methods.
Angular
Components
A component consists of tree parts:
 A Template
 A Decorator
 A TypeScript class
Template
You define a
component's view
with its
companion template.
A template is a form
of HTML that tells
Angular how to
render the
component.
Template
Metadata
Metadata tells Angular how to process a class.
To tell Angular that it’s a component, attach metadata to
the class.
In TypeScript, you attach metadata by using a decorator
Component class
Components are the main building
blocks for Angular applications. Each
component consists of: An HTML
template that declares what renders
on the page. A TypeScript class that
defines behavior. A CSS selector that
defines how the component is used
in a template
Template – Data binding
Without a framework, you would be responsible for pushing data values
into the HTML controls and turning user responses into actions and value
updates.
Angular supports data binding, a
mechanism for coordinating parts of
a template with parts of a
component.
Template – Data binding
Template – Data binding
Template – Data binding
Data binding plays an important
role in communication between a
template and its component.
But data binding is also important
for communication between parent
and child components.
Directives
Angular templates are dynamic. When Angular renders them,
it transforms the DOM according to the instructions given
by directives.
A directive is a class with a @Directive decorator. A
component is a directive-with-a-template; a
@Component decorator is actually a @Directive
decorator extended with template-oriented features.
Two other kinds of directives
exist: structural and attribute directives.
Directives - Structural
Structural directives alter layout by adding, removing, and replacing
elements in DOM.
Directives - Attribute
Attribute directives alter the appearance or behavior of an existing
element. In templates they look like regular HTML attributes, hence
the name.
Services
• Service is a broad category encompassing any value,
function, or feature that your application needs.
• Almost anything can be a service. A service is typically a
TypeScript class with a narrow, well-defined purpose, but
can just as well be a function or value
• Services should contain the business logic – not the
component.
Services
There is nothing specifically Angular about services. Angular has no
definition of a service. There is no service base class, and no place to
register a service.
Component classes should be lean. They don't fetch data from the
server, validate user input, or log directly to the console. They
delegate such tasks to services.
A component's job is to enable the user experience and nothing more.
It mediates between the view (rendered by the template) and the
application logic (which often includes some notion of a model). A good
component presents properties and methods for data binding. It
delegates everything nontrivial to services.
Services
Here's an example of a service class that logs to the browser console:
Dependency Injection
Dependency injection is a way to supply a new instance of a class with
the dependencies it requires. Most dependencies are services.
Angular uses dependency injection to provide new components with
the services they need.
Angular can tell which services a
component needs by looking at the
types of its constructor parameters.
Dependency Injection
When Angular creates a component, it first asks an injector for the services that the
component requires.
An injector maintains a container of service instances that it has previously created. If a
requested service instance is not in the container, the injector makes one and adds it to the
container before returning the service to Angular. When all requested services have been
resolved and returned, Angular can call the component's constructor with those services as
arguments. This is dependency injection.
Injector & Providers
We must register a service provider with the injector,
otherwise it don’t know how to create the service.
A provider is something that can create or return a service,
typically the service class itself.
You can register providers in modules or in components.
Injector & Providers
In general, add providers to the AppModule (root module) so
that the same instance of a service is available everywhere.
Injector & Providers
Alternatively, register at a component level in the
providers property of the @Component metadata:
Registering at a component level means you get a new instance of the
service with each new instance of that component, and you hides the
provider from other components and modules.
Input & Output
Component interaction
Passing data from parent to child using:
@Input( ) and property-binding
Passing data from child to parent using:
@Output( ) , EventEmitter and event-binding
(The parent listens for child event)
Parent to child - @Input()
ParentComponent
parentProperty : T
<child-component [childProperty] = ”parentProperty”><child…..
ChildComponent
@Input( ) childProperty : T
<p> {{childProperty }} </p>
[childProperty] = ”parentProperty”
Property-binding in parents html:
Child to parent - @Output()
ParentComponent
parentProperty : T
<child-component (eventEmitter) = ”eventHandler($event)” ><child…..
ChildComponent
@Output( ) eventEmitter = new EventEmitter<T>()
<p> (someEvent)=”someMethod(‘someValue’)” </p>
(eventEmitter) = ”eventHandler($event)”
Event-binding in parents html in the child-selector:
eventHandler (fromChild : T) {this. parentProperty=fromChild;}
someMethod(value : T ){this.eventEmitter.emit(value)}
Event-binding in child html:
(someEvent)=”someMethod(‘someValue’)”
@Input() - @Output()
Don’t forget the imports !
import { Component, Output, EventEmitter } from '@angular/core';
import { Component, Input } from '@angular/core';
Routing & navigation
The browser is a familiar model of application navigation:
•Enter a URL in the address bar and the browser navigates to
a corresponding page.
•Click links on the page and the browser navigates to a new page.
•Click the browser's back and forward buttons and the browser
navigates backward and forward through the history of pages you've seen.
The Angular Router ("the router") borrows from this model.
Routing & navigation
Routing is not a part of the core package, but:
@angular/router eg.
import { RouterModule, Routes } from '@angular/router';
A route describes a relation between the URL and a component eg.
http://localhost:4500/movie-list
{ path: 'movie-list', component: MovieListComponent },
The router module
The RouterModule is not imported in the root module, we
create and import our own module.
const appRoutes: Routes = [
{ path: 'movie-list', component: MovieListComponent },
{ path: 'movie-detail/:Title', component: MovieDetailComponent }, …
@NgModule({
imports: [ CommonModule, RouterModule.forRoot(appRoutes)],
exports: [ RouterModule ], …
Import the router module
The configured router module is imported into the
AppModule.
@NgModule({
declarations: [ AppComponent, MovieListComponent, … ],
imports: [ BrowserModule, FormsModule, HttpModule, AppRouterModule ],
Feature modules can (should) have routing as well. Then we use
RouteModule.forChild(… ) (instead of forRoot(… ))
RouterModule - Overview
Navigating
Navigate programmatically (imperatively) by injecting the
Router via the constructor:
constructor(private movieService : MovieService,
private route: ActivatedRoute,
private router: Router) { },
and call the router.navigate method:
public gotoMovies(){ this.router.navigate(['/movie-list']); }
Navigating
Navigate using the routerLink attribute directive in the template:
<nav class="nav navbar-nav">
<a routerLink="/movie-list" routerLinkActive="active">Movies</a>
<a routerLink="/under-construction" routerLinkActive="active">Admin</a>
……….
</nav>
The router displays each component immediately below the <router-outlet></router-outlet>
as we navigate through the application :
<div class="container">
<router-outlet></router-outlet>
</div>
HttpService

More Related Content

Similar to 17612235.ppt

Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in AngularAlexe Bogdan
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJSAustin Condiff
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type scriptRavi Mone
 
Modern webtechnologies
Modern webtechnologiesModern webtechnologies
Modern webtechnologiesBesjan Xhika
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesMarios Fakiolas
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Get Information about Angular Component- Technical Chamber.pdf
Get Information about Angular Component- Technical Chamber.pdfGet Information about Angular Component- Technical Chamber.pdf
Get Information about Angular Component- Technical Chamber.pdfNishaadequateinfosof
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript Rohit Bishnoi
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Angular Interview Question & Answers PDF By ScholarHat
Angular Interview Question & Answers PDF By ScholarHatAngular Interview Question & Answers PDF By ScholarHat
Angular Interview Question & Answers PDF By ScholarHatScholarhat
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfJohnLeo57
 

Similar to 17612235.ppt (20)

Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJS
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Modern webtechnologies
Modern webtechnologiesModern webtechnologies
Modern webtechnologies
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directives
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Get Information about Angular Component- Technical Chamber.pdf
Get Information about Angular Component- Technical Chamber.pdfGet Information about Angular Component- Technical Chamber.pdf
Get Information about Angular Component- Technical Chamber.pdf
 
Angular Directive.pptx
Angular Directive.pptxAngular Directive.pptx
Angular Directive.pptx
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
Angular Interview Question & Answers PDF By ScholarHat
Angular Interview Question & Answers PDF By ScholarHatAngular Interview Question & Answers PDF By ScholarHat
Angular Interview Question & Answers PDF By ScholarHat
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 

Recently uploaded

08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking MenDelhi Call girls
 
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改atducpo
 
Plan d'orientations stratégiques rugby féminin
Plan d'orientations stratégiques rugby fémininPlan d'orientations stratégiques rugby féminin
Plan d'orientations stratégiques rugby fémininThibaut TATRY
 
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改atducpo
 
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024HechemLaameri
 
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdf
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdfJORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdf
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdfArturo Pacheco Alvarez
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfArturo Pacheco Alvarez
 
08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking MenDelhi Call girls
 
ppt on Myself, Occupation and my Interest
ppt on Myself, Occupation and my Interestppt on Myself, Occupation and my Interest
ppt on Myself, Occupation and my InterestNagaissenValaydum
 
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxAlbania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxWorld Wide Tickets And Hospitality
 
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣anilsa9823
 
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...gurkirankumar98700
 
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...Eticketing.co
 
Dubai Call Girls Bikni O528786472 Call Girls Dubai Ebony
Dubai Call Girls Bikni O528786472 Call Girls Dubai EbonyDubai Call Girls Bikni O528786472 Call Girls Dubai Ebony
Dubai Call Girls Bikni O528786472 Call Girls Dubai Ebonyhf8803863
 
08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking MenDelhi Call girls
 
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...World Wide Tickets And Hospitality
 

Recently uploaded (20)

Call Girls In RK Puram 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In RK Puram 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In RK Puram 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In RK Puram 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Call Girls In Vasundhara 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Vasundhara 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Vasundhara 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Vasundhara 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men08448380779 Call Girls In Lajpat Nagar Women Seeking Men
08448380779 Call Girls In Lajpat Nagar Women Seeking Men
 
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
大学学位办理《原版美国USD学位证书》圣地亚哥大学毕业证制作成绩单修改
 
Plan d'orientations stratégiques rugby féminin
Plan d'orientations stratégiques rugby fémininPlan d'orientations stratégiques rugby féminin
Plan d'orientations stratégiques rugby féminin
 
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改
大学假文凭《原版英国Imperial文凭》帝国理工学院毕业证制作成绩单修改
 
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Anna Nagar Phone 🍆 8250192130 👅 celebrity escorts service
 
Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024Tableaux 9ème étape circuit fédéral 2024
Tableaux 9ème étape circuit fédéral 2024
 
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdf
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdfJORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdf
JORNADA 4 LIGA MURO 2024TUXTEPEC1234.pdf
 
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdfJORNADA 5 LIGA MURO 2024INSUGURACION.pdf
JORNADA 5 LIGA MURO 2024INSUGURACION.pdf
 
08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men08448380779 Call Girls In IIT Women Seeking Men
08448380779 Call Girls In IIT Women Seeking Men
 
ppt on Myself, Occupation and my Interest
ppt on Myself, Occupation and my Interestppt on Myself, Occupation and my Interest
ppt on Myself, Occupation and my Interest
 
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docxAlbania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
Albania Vs Spain Albania is Loaded with Defensive Talent on their Roster.docx
 
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service  🧣
CALL ON ➥8923113531 🔝Call Girls Telibagh Lucknow best Night Fun service 🧣
 
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...
Jankipuram / Call Girls Lucknow | Whatsapp No 🫗 8923113531 🎳 VIP Escorts Serv...
 
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Noida Extension @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...
Italy vs Albania Tickets: Italy's Quest for Euro Cup Germany History, Defendi...
 
Dubai Call Girls Bikni O528786472 Call Girls Dubai Ebony
Dubai Call Girls Bikni O528786472 Call Girls Dubai EbonyDubai Call Girls Bikni O528786472 Call Girls Dubai Ebony
Dubai Call Girls Bikni O528786472 Call Girls Dubai Ebony
 
08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men08448380779 Call Girls In International Airport Women Seeking Men
08448380779 Call Girls In International Airport Women Seeking Men
 
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
Spain Vs Italy 20 players confirmed for Spain's Euro 2024 squad, and three po...
 

17612235.ppt

  • 2. What is Angular ?  Angular is a platform that helps you create advanced web applications in HTML using Typescript (Dart or ES5).  It helps you to structure your code, separate your concerns and remove trivial code.
  • 3. Angular Modularity Angular applications are based on Modules. Angular Modules helps organizing the application into cohesive blocks of functionality. A module is implemented as a class. Declares which components, services etc that belongs together.
  • 4. Angular AppModule Every Angular applications have at least one module - the RootModule by convention named AppModule. Larger Angular applications will have feature and route modules as well.
  • 7. Angular Architecture The architecture diagram identifies the eight main building blocks of an Angular application:  Modules  Components  Templates  Metadata  Data binding  Directives  Services  Dependency injection
  • 8. Angular Components  A component controls a piece of the screen called a view.  A component's application logic—what it does to support the view—is defined in a class. The class interacts with the view through an API of properties and methods.
  • 9. Angular Components A component consists of tree parts:  A Template  A Decorator  A TypeScript class
  • 10. Template You define a component's view with its companion template. A template is a form of HTML that tells Angular how to render the component.
  • 12. Metadata Metadata tells Angular how to process a class. To tell Angular that it’s a component, attach metadata to the class. In TypeScript, you attach metadata by using a decorator
  • 13. Component class Components are the main building blocks for Angular applications. Each component consists of: An HTML template that declares what renders on the page. A TypeScript class that defines behavior. A CSS selector that defines how the component is used in a template
  • 14. Template – Data binding Without a framework, you would be responsible for pushing data values into the HTML controls and turning user responses into actions and value updates. Angular supports data binding, a mechanism for coordinating parts of a template with parts of a component.
  • 15. Template – Data binding
  • 16. Template – Data binding
  • 17. Template – Data binding Data binding plays an important role in communication between a template and its component. But data binding is also important for communication between parent and child components.
  • 18. Directives Angular templates are dynamic. When Angular renders them, it transforms the DOM according to the instructions given by directives. A directive is a class with a @Directive decorator. A component is a directive-with-a-template; a @Component decorator is actually a @Directive decorator extended with template-oriented features. Two other kinds of directives exist: structural and attribute directives.
  • 19. Directives - Structural Structural directives alter layout by adding, removing, and replacing elements in DOM.
  • 20. Directives - Attribute Attribute directives alter the appearance or behavior of an existing element. In templates they look like regular HTML attributes, hence the name.
  • 21. Services • Service is a broad category encompassing any value, function, or feature that your application needs. • Almost anything can be a service. A service is typically a TypeScript class with a narrow, well-defined purpose, but can just as well be a function or value • Services should contain the business logic – not the component.
  • 22. Services There is nothing specifically Angular about services. Angular has no definition of a service. There is no service base class, and no place to register a service. Component classes should be lean. They don't fetch data from the server, validate user input, or log directly to the console. They delegate such tasks to services. A component's job is to enable the user experience and nothing more. It mediates between the view (rendered by the template) and the application logic (which often includes some notion of a model). A good component presents properties and methods for data binding. It delegates everything nontrivial to services.
  • 23. Services Here's an example of a service class that logs to the browser console:
  • 24. Dependency Injection Dependency injection is a way to supply a new instance of a class with the dependencies it requires. Most dependencies are services. Angular uses dependency injection to provide new components with the services they need. Angular can tell which services a component needs by looking at the types of its constructor parameters.
  • 25. Dependency Injection When Angular creates a component, it first asks an injector for the services that the component requires. An injector maintains a container of service instances that it has previously created. If a requested service instance is not in the container, the injector makes one and adds it to the container before returning the service to Angular. When all requested services have been resolved and returned, Angular can call the component's constructor with those services as arguments. This is dependency injection.
  • 26. Injector & Providers We must register a service provider with the injector, otherwise it don’t know how to create the service. A provider is something that can create or return a service, typically the service class itself. You can register providers in modules or in components.
  • 27. Injector & Providers In general, add providers to the AppModule (root module) so that the same instance of a service is available everywhere.
  • 28. Injector & Providers Alternatively, register at a component level in the providers property of the @Component metadata: Registering at a component level means you get a new instance of the service with each new instance of that component, and you hides the provider from other components and modules.
  • 29. Input & Output Component interaction Passing data from parent to child using: @Input( ) and property-binding Passing data from child to parent using: @Output( ) , EventEmitter and event-binding (The parent listens for child event)
  • 30. Parent to child - @Input() ParentComponent parentProperty : T <child-component [childProperty] = ”parentProperty”><child….. ChildComponent @Input( ) childProperty : T <p> {{childProperty }} </p> [childProperty] = ”parentProperty” Property-binding in parents html:
  • 31. Child to parent - @Output() ParentComponent parentProperty : T <child-component (eventEmitter) = ”eventHandler($event)” ><child….. ChildComponent @Output( ) eventEmitter = new EventEmitter<T>() <p> (someEvent)=”someMethod(‘someValue’)” </p> (eventEmitter) = ”eventHandler($event)” Event-binding in parents html in the child-selector: eventHandler (fromChild : T) {this. parentProperty=fromChild;} someMethod(value : T ){this.eventEmitter.emit(value)} Event-binding in child html: (someEvent)=”someMethod(‘someValue’)”
  • 32. @Input() - @Output() Don’t forget the imports ! import { Component, Output, EventEmitter } from '@angular/core'; import { Component, Input } from '@angular/core';
  • 33. Routing & navigation The browser is a familiar model of application navigation: •Enter a URL in the address bar and the browser navigates to a corresponding page. •Click links on the page and the browser navigates to a new page. •Click the browser's back and forward buttons and the browser navigates backward and forward through the history of pages you've seen. The Angular Router ("the router") borrows from this model.
  • 34. Routing & navigation Routing is not a part of the core package, but: @angular/router eg. import { RouterModule, Routes } from '@angular/router'; A route describes a relation between the URL and a component eg. http://localhost:4500/movie-list { path: 'movie-list', component: MovieListComponent },
  • 35. The router module The RouterModule is not imported in the root module, we create and import our own module. const appRoutes: Routes = [ { path: 'movie-list', component: MovieListComponent }, { path: 'movie-detail/:Title', component: MovieDetailComponent }, … @NgModule({ imports: [ CommonModule, RouterModule.forRoot(appRoutes)], exports: [ RouterModule ], …
  • 36. Import the router module The configured router module is imported into the AppModule. @NgModule({ declarations: [ AppComponent, MovieListComponent, … ], imports: [ BrowserModule, FormsModule, HttpModule, AppRouterModule ], Feature modules can (should) have routing as well. Then we use RouteModule.forChild(… ) (instead of forRoot(… ))
  • 38. Navigating Navigate programmatically (imperatively) by injecting the Router via the constructor: constructor(private movieService : MovieService, private route: ActivatedRoute, private router: Router) { }, and call the router.navigate method: public gotoMovies(){ this.router.navigate(['/movie-list']); }
  • 39. Navigating Navigate using the routerLink attribute directive in the template: <nav class="nav navbar-nav"> <a routerLink="/movie-list" routerLinkActive="active">Movies</a> <a routerLink="/under-construction" routerLinkActive="active">Admin</a> ………. </nav> The router displays each component immediately below the <router-outlet></router-outlet> as we navigate through the application : <div class="container"> <router-outlet></router-outlet> </div>