SlideShare a Scribd company logo
AngularJS Custom Directive
Presented by
Md. Masud Rana
Topics
- What are directives?
- Angular built in directives.
- Types of directives.
- Convention to write a custom directive.
- Example of directive to start writing.
What are Directives?
Directives are markers on a DOM element
(such as an attribute, element name, comment
or CSS class) that tell AngularJS's HTML
compiler ($compile) to attach a specified
behavior to that DOM element or even
transform the DOM element and its children.
AngularJS Built in Directives
Angular comes with a set of these built-in
directives like
ngBind, ngModel, and ngClass etc.
Conventions to Write a Directive
- Case-sensitive (camelCase) normalized name(e.g.
ngModel.)
- HTML is case-insensitive, so directives in the DOM by
lower-case forms, typically using dash-delimited
attributes on DOM elements (e.g. ng-model)
- Strip x- and data- from the front of the element/attributes
- Convert the :, -, or _-delimited name to camelCase
Directive in HTML Template
<div ng-controller="Controller">
Hello <input ng-model='name'> <hr/>
<span ng-bind="name"></span> <br/>
<span ng:bind="name"></span> <br/>
<span ng_bind="name"></span> <br/>
<span data-ng-bind="name"></span> <br/>
<span x-ng-bind="name"></span> <br/>
</div>
Best Practice
Prefer using the dash-delimited format (e.g. ng-
bind for ngBind). If you want to use an HTML
validating tool, you can instead use the data-
prefixed version (e.g. data-ng-bind for ngBind).
The other forms shown above are accepted for
legacy reasons but we advise you to avoid
them.
Directive Types
1. Element names (HTML Tag)
2. Attributes
3. Class names and
4. Comments
Example of Directive Types
<my-dir></my-dir>
<span my-dir="exp"></span>
<!-- directive: my-dir exp -->
<span class="my-dir: exp;"></span>
Best Practice: Prefer using directives via tag name and
attributes over comment and class names. Doing so
generally makes it easier to determine what directives a
given element matches.
Instruction about Directives
1. Register a directive, use the module.directive
2. Directive name followed by a factory function
3. To avoid collisions with some future standard, it's best to
prefix your own directive names. For instance, if you
created a <carousel> directive, it would be problematic if
HTML7 introduced the same element. A two or three letter
prefix (e.g. btfCarousel) works well.
4. Do not prefix your own directives with ng
Writing Some Custom Directive
1. Replace static content
Demo: https://jsfiddle.net/masudcsesust04/nj25aznt/
2. Restricted directive
Demo: https://jsfiddle.net/masudcsesust04/fr0mncdg/
3. Isolated scope
Demo: https://jsfiddle.net/masudcsesust04/9vo0339s/
4. Wraps other elements
Demo: https://jsfiddle.net/masudcsesust04/5wdm8xk0/
5. Communicative directive
Demo: https://jsfiddle.net/masudcsesust04/0s5uztax/
Any questions?
Thank you!

More Related Content

PPTX
Basics of angular directive (Part - 1)
Vijay Kani
 
PDF
Angular custom directives
Alexe Bogdan
 
PPTX
Building AngularJS Custom Directives
Dan Wahlin
 
PPTX
BDOTNET AngularJs Directives - Uday
Udaya Kumar
 
PDF
Custom AngularJS Directives
yprodev
 
PPTX
Angular JS
John Temoty Roca
 
PDF
AngularJS Basic Training
Cornel Stefanache
 
PPTX
Angular js
Manav Prasad
 
Basics of angular directive (Part - 1)
Vijay Kani
 
Angular custom directives
Alexe Bogdan
 
Building AngularJS Custom Directives
Dan Wahlin
 
BDOTNET AngularJs Directives - Uday
Udaya Kumar
 
Custom AngularJS Directives
yprodev
 
Angular JS
John Temoty Roca
 
AngularJS Basic Training
Cornel Stefanache
 
Angular js
Manav Prasad
 

What's hot (20)

PPTX
Getting Started with Angular JS
Akshay Mathur
 
KEY
AngularJS for designers and developers
Kai Koenig
 
PPTX
Understanding angular js
Aayush Shrestha
 
PPTX
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
PPTX
Introduction to AngularJs
murtazahaveliwala
 
PPTX
Angular Js Basics
أحمد عبد الوهاب
 
PPTX
The AngularJS way
Boyan Mihaylov
 
PPTX
Angular js architecture (v1.4.8)
Gabi Costel Lapusneanu
 
PPTX
Angular JS - Introduction
Sagar Acharya
 
PPT
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
PPTX
Modular javascript
Zain Shaikh
 
PPTX
Angular js
Dinusha Nandika
 
PPTX
Angular js
Behind D Walls
 
PPTX
Angular Presentation
Adam Moore
 
PPTX
Practical AngularJS
Wei Ru
 
PDF
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
PPTX
Introduction to Angularjs
Manish Shekhawat
 
PPTX
Angular js
sanjay joshi
 
PPTX
Angular js
ParmarAnisha
 
PPTX
Why angular js Framework
Sakthi Bro
 
Getting Started with Angular JS
Akshay Mathur
 
AngularJS for designers and developers
Kai Koenig
 
Understanding angular js
Aayush Shrestha
 
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
Introduction to AngularJs
murtazahaveliwala
 
Angular Js Basics
أحمد عبد الوهاب
 
The AngularJS way
Boyan Mihaylov
 
Angular js architecture (v1.4.8)
Gabi Costel Lapusneanu
 
Angular JS - Introduction
Sagar Acharya
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
Modular javascript
Zain Shaikh
 
Angular js
Dinusha Nandika
 
Angular js
Behind D Walls
 
Angular Presentation
Adam Moore
 
Practical AngularJS
Wei Ru
 
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
Introduction to Angularjs
Manish Shekhawat
 
Angular js
sanjay joshi
 
Angular js
ParmarAnisha
 
Why angular js Framework
Sakthi Bro
 
Ad

Viewers also liked (20)

PDF
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
PDF
AngularJS Custom Directives
yprodev
 
PPTX
Building an End-to-End AngularJS Application
Dan Wahlin
 
PPTX
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Dan Wahlin
 
PDF
Angular promises and http
Alexe Bogdan
 
PPTX
Angular Deep Directive
Henry Tao
 
PPT
Coffee@DBG - Exploring Angular JS
Deepu S Nath
 
PPTX
AngularJs presentation
Phan Tuan
 
PDF
AngularJS - TechTalk 3/2/2014
Spyros Ioakeimidis
 
PPTX
AngularJS in 60ish Minutes
Dan Wahlin
 
PPT
Using jQuery Templates
Dan Wahlin
 
PPTX
JavaScript Patterns to Cleanup your Code
Dan Wahlin
 
PDF
Angular Promises and Advanced Routing
Alexe Bogdan
 
PPTX
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Dan Wahlin
 
PPTX
Step by Step - AngularJS
Infragistics
 
PPTX
Development Trends - What's New in the World of Web Development
Dan Wahlin
 
PPTX
Integrating Security Roles into Microsoft Silverlight Applications
Dan Wahlin
 
PPTX
Planificación y organización de dominio
lilidani103
 
PPTX
Spa Architecture with Durandal and Friends
Johnny Tordgeman
 
PDF
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
AngularJS Custom Directives
yprodev
 
Building an End-to-End AngularJS Application
Dan Wahlin
 
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Dan Wahlin
 
Angular promises and http
Alexe Bogdan
 
Angular Deep Directive
Henry Tao
 
Coffee@DBG - Exploring Angular JS
Deepu S Nath
 
AngularJs presentation
Phan Tuan
 
AngularJS - TechTalk 3/2/2014
Spyros Ioakeimidis
 
AngularJS in 60ish Minutes
Dan Wahlin
 
Using jQuery Templates
Dan Wahlin
 
JavaScript Patterns to Cleanup your Code
Dan Wahlin
 
Angular Promises and Advanced Routing
Alexe Bogdan
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Dan Wahlin
 
Step by Step - AngularJS
Infragistics
 
Development Trends - What's New in the World of Web Development
Dan Wahlin
 
Integrating Security Roles into Microsoft Silverlight Applications
Dan Wahlin
 
Planificación y organización de dominio
lilidani103
 
Spa Architecture with Durandal and Friends
Johnny Tordgeman
 
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Ad

Similar to AngularJS custom directive (20)

PPTX
Directives
Roshan Warke
 
PDF
Angular directives and pipes
Knoldus Inc.
 
PPTX
Angular Directives
Malla Reddy University
 
PPTX
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
PDF
Angular Directives from Scratch
Christian Lilley
 
PPTX
angularJs Workshop
Ran Wahle
 
PDF
Intro to Angular.JS Directives
Christian Lilley
 
DOCX
Directives
Brajesh Yadav
 
PDF
Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...
Edureka!
 
PPTX
AngularJS - GrapeCity Echo Tokyo
Chris Bannon
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PDF
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Edureka!
 
PPTX
Agular 2 - 6 Directives
Rajneeshksharma
 
PPTX
AIT SEMINAR.pptx
bhavyag24
 
PPTX
Angular Directive.pptx
AshokKumar616995
 
PPTX
AngularJS
Malin De Silva
 
PDF
Angular.js Primer in Aalto University
SC5.io
 
PPTX
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
murtazahaveliwala
 
PPTX
AngularJS
LearningTech
 
Directives
Roshan Warke
 
Angular directives and pipes
Knoldus Inc.
 
Angular Directives
Malla Reddy University
 
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Angular Directives from Scratch
Christian Lilley
 
angularJs Workshop
Ran Wahle
 
Intro to Angular.JS Directives
Christian Lilley
 
Directives
Brajesh Yadav
 
Angular 4 Directives | Angular 4 Tutorial For Beginners | Angular 4 Directive...
Edureka!
 
AngularJS - GrapeCity Echo Tokyo
Chris Bannon
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Edureka!
 
Agular 2 - 6 Directives
Rajneeshksharma
 
AIT SEMINAR.pptx
bhavyag24
 
Angular Directive.pptx
AshokKumar616995
 
AngularJS
Malin De Silva
 
Angular.js Primer in Aalto University
SC5.io
 
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
murtazahaveliwala
 
AngularJS
LearningTech
 

More from Nascenia IT (20)

PPTX
Exploring DeepSeek A Hands-On Dive & How to Adapt the AI Surge.pptx
Nascenia IT
 
PPTX
AI Tools for Productivity: Exploring Prompt Engineering and Key Features
Nascenia IT
 
PDF
Introduction to basic data analytics tools
Nascenia IT
 
PPTX
Communication workshop in nascenia
Nascenia IT
 
PPTX
The Art of Statistical Deception
Nascenia IT
 
PDF
করোনায় কী করি!
Nascenia IT
 
PPTX
GDPR compliance expectations from the development team
Nascenia IT
 
PPTX
Writing Clean Code
Nascenia IT
 
PPTX
History & Introduction of Neural Network and use of it in Computer Vision
Nascenia IT
 
PPTX
Ruby on Rails: Coding Guideline
Nascenia IT
 
PPTX
iphone 11 new features
Nascenia IT
 
PPTX
Software quality assurance and cyber security
Nascenia IT
 
PPTX
Job Market Scenario For Freshers
Nascenia IT
 
PPTX
Modern Frontend Technologies (BEM, Retina)
Nascenia IT
 
PPTX
CSS for Developers
Nascenia IT
 
PPTX
Big commerce app development
Nascenia IT
 
PPTX
Integrating QuickBooks Desktop with Rails Application
Nascenia IT
 
PPTX
Shopify
Nascenia IT
 
PPTX
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
PPTX
Clean code
Nascenia IT
 
Exploring DeepSeek A Hands-On Dive & How to Adapt the AI Surge.pptx
Nascenia IT
 
AI Tools for Productivity: Exploring Prompt Engineering and Key Features
Nascenia IT
 
Introduction to basic data analytics tools
Nascenia IT
 
Communication workshop in nascenia
Nascenia IT
 
The Art of Statistical Deception
Nascenia IT
 
করোনায় কী করি!
Nascenia IT
 
GDPR compliance expectations from the development team
Nascenia IT
 
Writing Clean Code
Nascenia IT
 
History & Introduction of Neural Network and use of it in Computer Vision
Nascenia IT
 
Ruby on Rails: Coding Guideline
Nascenia IT
 
iphone 11 new features
Nascenia IT
 
Software quality assurance and cyber security
Nascenia IT
 
Job Market Scenario For Freshers
Nascenia IT
 
Modern Frontend Technologies (BEM, Retina)
Nascenia IT
 
CSS for Developers
Nascenia IT
 
Big commerce app development
Nascenia IT
 
Integrating QuickBooks Desktop with Rails Application
Nascenia IT
 
Shopify
Nascenia IT
 
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
Clean code
Nascenia IT
 

Recently uploaded (20)

PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Software Development Methodologies in 2025
KodekX
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

AngularJS custom directive

  • 2. Topics - What are directives? - Angular built in directives. - Types of directives. - Convention to write a custom directive. - Example of directive to start writing.
  • 3. What are Directives? Directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element or even transform the DOM element and its children.
  • 4. AngularJS Built in Directives Angular comes with a set of these built-in directives like ngBind, ngModel, and ngClass etc.
  • 5. Conventions to Write a Directive - Case-sensitive (camelCase) normalized name(e.g. ngModel.) - HTML is case-insensitive, so directives in the DOM by lower-case forms, typically using dash-delimited attributes on DOM elements (e.g. ng-model) - Strip x- and data- from the front of the element/attributes - Convert the :, -, or _-delimited name to camelCase
  • 6. Directive in HTML Template <div ng-controller="Controller"> Hello <input ng-model='name'> <hr/> <span ng-bind="name"></span> <br/> <span ng:bind="name"></span> <br/> <span ng_bind="name"></span> <br/> <span data-ng-bind="name"></span> <br/> <span x-ng-bind="name"></span> <br/> </div>
  • 7. Best Practice Prefer using the dash-delimited format (e.g. ng- bind for ngBind). If you want to use an HTML validating tool, you can instead use the data- prefixed version (e.g. data-ng-bind for ngBind). The other forms shown above are accepted for legacy reasons but we advise you to avoid them.
  • 8. Directive Types 1. Element names (HTML Tag) 2. Attributes 3. Class names and 4. Comments
  • 9. Example of Directive Types <my-dir></my-dir> <span my-dir="exp"></span> <!-- directive: my-dir exp --> <span class="my-dir: exp;"></span> Best Practice: Prefer using directives via tag name and attributes over comment and class names. Doing so generally makes it easier to determine what directives a given element matches.
  • 10. Instruction about Directives 1. Register a directive, use the module.directive 2. Directive name followed by a factory function 3. To avoid collisions with some future standard, it's best to prefix your own directive names. For instance, if you created a <carousel> directive, it would be problematic if HTML7 introduced the same element. A two or three letter prefix (e.g. btfCarousel) works well. 4. Do not prefix your own directives with ng
  • 11. Writing Some Custom Directive 1. Replace static content Demo: https://jsfiddle.net/masudcsesust04/nj25aznt/ 2. Restricted directive Demo: https://jsfiddle.net/masudcsesust04/fr0mncdg/ 3. Isolated scope Demo: https://jsfiddle.net/masudcsesust04/9vo0339s/ 4. Wraps other elements Demo: https://jsfiddle.net/masudcsesust04/5wdm8xk0/ 5. Communicative directive Demo: https://jsfiddle.net/masudcsesust04/0s5uztax/