SlideShare a Scribd company logo
1 of 36
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Agenda
❖ Why we need Angular Directive?
❖ What is Angular Directive?
❖ Types of Angular Directive
❖ Built-in Angular Directives
❖ Working with Custom Angular Directives
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why We Need Angular Directive?
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Component 1
Component 2
{ }
{ }
Component 4
Component …
Component 3
Component …
{ }
{ }
{ }
{ }
Why we need Directive?
Component 1
Component 2
{ }
{ }
Component 4
Component …
Component 3
Component …
{ }
{ }
{ }
{ }
Changing code for Component 1
Similarly changing code for each components individually…
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Component 1
Component 2
{ }
{ }
Component 4
Component …
Component 3
Component …
{ }
{ }
{ }
{ }
Component 1
Component 2
{ }
{ }
Component 4
Component …
Component 3
Component …
{ }
{ }
{ }
{ }
DirectiveCreate a with required
behavior
Just Import the Directive to all
Components
Directives can be imported anywhere providing similar functionality
Directive
Directive
Directive
Directive
Directive
Directive
Why we need Directive?
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Directive?
Code modular & manageable
Reusable code
Separating that code out from the view, helps developer to
focus on UI and application logic separately
Available as a stand-alone reusable unit
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
What is Angular Directive?
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Directives Introduction
Directives extend HTML
with new attributes
DOM is transformed according
to directives instructions
Appear within an element tag
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Directives Introduction
Angular provides a set of built-in
directives which offers functionality
Create custom directives
A directive is a class with a
@Directive decorator
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Types of Angular Directive
www.edureka.co/angular-jsEDUREKA ANGULAR-JS CERTIFICATION TRAINING
Types of Angular Directives
Components
1
Structural Directives
2
Attributes Directive
3
Directives with a template
Adds & removes DOM elements to change DOM layout
Changes the appearance or behavior of an element
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Component Directive
@Component decorator is a @Directive decorator
extended with template-oriented features
A component is technically a directive-with-a-template
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Structural Directives
Structural directives alter layout by adding, removing, and replacing elements in DOM.
*ngFor tells Angular to stamp out one
<li> per course in the courses list.
*ngIf includes the CourseDetail
component only if a selected course exists
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Attribute Directives
Attribute Directive alter the appearance or
behavior of an existing element
Displays value property and responds to
changing events
ngModel modifies the behavior of an
existing element
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-In Angular Directives
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass NgClass is used for class binding – adding or
removing several classes
Adding an NgClass property binding sets the
element's classes accordingly
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass
NgStyle helps in style binding
NgStyle directive is a better choice while
setting many inline styles
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass
Adds an element subtree to the DOM by
binding an NgIf directive
Binding to a false expression removes the
element subtree from the DOM
VISIBILITY AND NGIF ARE NOT THE SAME
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass
NgSwitch displays one element from a set of
element trees based on conditions
Returns a switch value
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass
At any particular moment, at most one of these
spans is in the DOM
3 collaborating directives are at work here:
ngSwitch
1
ngSwitchCase
2
ngSwitchDefault
3
bound to an expression that returns the switch value
bound to an expression returning a match value
a marker attribute on the default element
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Angular Directives
NgStyle
NgIf
NgSwitch
NgFor
NgClass
NgFor is a repeater directive - presents a list of
items
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
* and template
* modify HTML layout with the help of
templates
NgFor, NgIf, and NgSwitch adds and removes
elements
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Directive
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
provides the functionality of
the @Directive decorator.
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
It can access the DOM
element
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Subscribe to events of the
DOM element
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Allows data to flow from the binding
expression into the directive
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Contains the directive
metadata in a
configuration object
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Identifies the HTML in the template
that is associated with the directive
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Directive Class that performs
operation
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Grants direct access to the DOM
element through
its nativeElement property
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Attribute Directive
Listens to the event and perform
accordingly
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Custom Structural Directive
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Hands-On
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Thank You …
Questions/Queries/Feedback

More Related Content

What's hot

What's hot (20)

Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
Angular
AngularAngular
Angular
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Angular
AngularAngular
Angular
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019RxJS & Angular Reactive Forms @ Codemotion 2019
RxJS & Angular Reactive Forms @ Codemotion 2019
 
Angular overview
Angular overviewAngular overview
Angular overview
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Module
 
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | EdurekaAngular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
Angular 4 Tutorial | What's New In Angular 4 | Angular Training | Edureka
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 

Similar to Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular Training | Edureka

Similar to Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular Training | Edureka (20)

Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...
Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...
Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...
 
Angular Directive.pptx
Angular Directive.pptxAngular Directive.pptx
Angular Directive.pptx
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Angular TS(typescript)
Angular TS(typescript)Angular TS(typescript)
Angular TS(typescript)
 
Building Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET CoreBuilding Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET Core
 
Introduction to angular 2
Introduction to angular 2Introduction to angular 2
Introduction to angular 2
 
Wt unit 5 client &amp; server side framework
Wt unit 5 client &amp; server side frameworkWt unit 5 client &amp; server side framework
Wt unit 5 client &amp; server side framework
 
Ng talk
Ng talkNg talk
Ng talk
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
 
Angular js 2.0 beta
Angular js 2.0 betaAngular js 2.0 beta
Angular js 2.0 beta
 
Angular 2 Training | Angular 2 Tutorial For Beginners | Angular Certification...
Angular 2 Training | Angular 2 Tutorial For Beginners | Angular Certification...Angular 2 Training | Angular 2 Tutorial For Beginners | Angular Certification...
Angular 2 Training | Angular 2 Tutorial For Beginners | Angular Certification...
 
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
 
Directives.pptx
Directives.pptxDirectives.pptx
Directives.pptx
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
 
AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directives
 
Angular2
Angular2Angular2
Angular2
 

More from Edureka!

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular Training | Edureka

  • 1.
  • 2. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Agenda ❖ Why we need Angular Directive? ❖ What is Angular Directive? ❖ Types of Angular Directive ❖ Built-in Angular Directives ❖ Working with Custom Angular Directives
  • 3. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why We Need Angular Directive?
  • 4. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Component 1 Component 2 { } { } Component 4 Component … Component 3 Component … { } { } { } { } Why we need Directive? Component 1 Component 2 { } { } Component 4 Component … Component 3 Component … { } { } { } { } Changing code for Component 1 Similarly changing code for each components individually…
  • 5. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Component 1 Component 2 { } { } Component 4 Component … Component 3 Component … { } { } { } { } Component 1 Component 2 { } { } Component 4 Component … Component 3 Component … { } { } { } { } DirectiveCreate a with required behavior Just Import the Directive to all Components Directives can be imported anywhere providing similar functionality Directive Directive Directive Directive Directive Directive Why we need Directive?
  • 6. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Directive? Code modular & manageable Reusable code Separating that code out from the view, helps developer to focus on UI and application logic separately Available as a stand-alone reusable unit
  • 7. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js What is Angular Directive?
  • 8. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Directives Introduction Directives extend HTML with new attributes DOM is transformed according to directives instructions Appear within an element tag
  • 9. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Directives Introduction Angular provides a set of built-in directives which offers functionality Create custom directives A directive is a class with a @Directive decorator
  • 10. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Types of Angular Directive
  • 11. www.edureka.co/angular-jsEDUREKA ANGULAR-JS CERTIFICATION TRAINING Types of Angular Directives Components 1 Structural Directives 2 Attributes Directive 3 Directives with a template Adds & removes DOM elements to change DOM layout Changes the appearance or behavior of an element
  • 12. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Component Directive @Component decorator is a @Directive decorator extended with template-oriented features A component is technically a directive-with-a-template
  • 13. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Structural Directives Structural directives alter layout by adding, removing, and replacing elements in DOM. *ngFor tells Angular to stamp out one <li> per course in the courses list. *ngIf includes the CourseDetail component only if a selected course exists
  • 14. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Attribute Directives Attribute Directive alter the appearance or behavior of an existing element Displays value property and responds to changing events ngModel modifies the behavior of an existing element
  • 15. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-In Angular Directives
  • 16. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass NgClass is used for class binding – adding or removing several classes Adding an NgClass property binding sets the element's classes accordingly
  • 17. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass NgStyle helps in style binding NgStyle directive is a better choice while setting many inline styles
  • 18. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass Adds an element subtree to the DOM by binding an NgIf directive Binding to a false expression removes the element subtree from the DOM VISIBILITY AND NGIF ARE NOT THE SAME
  • 19. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass NgSwitch displays one element from a set of element trees based on conditions Returns a switch value
  • 20. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass At any particular moment, at most one of these spans is in the DOM 3 collaborating directives are at work here: ngSwitch 1 ngSwitchCase 2 ngSwitchDefault 3 bound to an expression that returns the switch value bound to an expression returning a match value a marker attribute on the default element
  • 21. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Angular Directives NgStyle NgIf NgSwitch NgFor NgClass NgFor is a repeater directive - presents a list of items
  • 22. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js * and template * modify HTML layout with the help of templates NgFor, NgIf, and NgSwitch adds and removes elements
  • 23. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive
  • 24. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Directive
  • 25. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive provides the functionality of the @Directive decorator.
  • 26. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive It can access the DOM element
  • 27. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Subscribe to events of the DOM element
  • 28. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Allows data to flow from the binding expression into the directive
  • 29. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Contains the directive metadata in a configuration object
  • 30. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Identifies the HTML in the template that is associated with the directive
  • 31. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Directive Class that performs operation
  • 32. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Grants direct access to the DOM element through its nativeElement property
  • 33. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Attribute Directive Listens to the event and perform accordingly
  • 34. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Custom Structural Directive
  • 35. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Hands-On
  • 36. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Thank You … Questions/Queries/Feedback