SlideShare uma empresa Scribd logo
1 de 34
Dan Wahlin
Dan Wahlin
Blog
http://weblogs.asp.net/dwahlin
Twitter
@DanWahlin
Get 60% off the video course!
http://tinyurl.com/ngDirectives60
http://codepen.io/danwahlin
https://github.com/DanWahlin/AngularCustomDirectives
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Directive Examples
Key AngularJS Directives
Application
• ng-app
• ng-controller
Forms
• ng-maxlength
• ng-minlength
• ng-pattern
• ng-required
• ng-submit
Templates
• ng-disabled
• ng-cloak
• ng-hide
• ng-if
• ng-repeat
• ng-show
• ng-switch
• ng-view
Data Binding
• ng-bind
• ng-href
• ng-init
• ng-model
• ng-src
• ng-style
Behavior
• ng-blur
• ng-change
• ng-checked
• ng-click
• ng-key*
• ng-mouse*
Using AngularJS Directives
• Attribute directives
<span my-dir="exp"></span>
• Element directives
<my-dir></my-dir>
• CSS class directives
<span class="my-dir: exp;"></span>
• Comment directives
<!-- directive: my-dir exp -->
Custom Directives
Data-Driven Directives
All about data, using
other directives and a
controller
DOM-Driven Directives
All about DOM
Manipulation
Behavior-Driven
Directives
All about events and
behaviors
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Directive Examples
templateUrl
scope
restrict template
controller link
angular.module('moduleName')
.directive('myDirective', function () {
return {
restrict: 'EA', //E = element, A = attribute, C = class, M = comment
scope: {
//@ reads the attribute string value,
//= provides two-way binding,
//& works with functions
title: '@'
},
template: '<div>{{ myVal }}</div>',
templateUrl: 'mytemplate.html',
controller: controller,
link: function ($scope, element, attrs) { } //DOM manipulation
}
});
http://docs.angularjs.org/api/ng/service/$compile
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Directive Examples
Shared Scope
Parent Scope
Child Scope
Isolate Scope
Parent Scope
Child Scope
Wall Blocks Parent Scope
Controller
$scope.customers=[];
Depends on parent scope
$scope.customers=[];
Directive
Shared
Controller
$scope.customers=[];
Isolated from parent scope
$scope.customers=[];
$scope.isolated = true;
Directive
Not Shared
Shared Scope Isolate Scope
Shared Scope Directive Example
var app = angular.module('myModule', []);
app.controller('Controller', ['$scope', function ($scope) {
$scope.customer = {
name: 'David',
street: '1234 Anywhere St.'
};
}]);
app.directive('sharedScope', function () {
return {
template: 'Name: {{customer.name}} Street: {{customer.street}}'
};
});
Scope is inherited
<div shared-scope></div>
Isolating Scope in Directives
angular.module('myModule')
.directive('isolateScope', function () {
return {
scope: {}, //isolate scope
template: 'Name: {{customer.name}} Street: ' +
'{{customer.street}}'
};
});
<div isolate-scope></div>
No data will display!
Hi, I'm Dan
String with one-way binding
@
$scope.first='James';
Directive can access a string value
scope: { name: '@' }
Directive
@ isolate scope property
<my-directive name="{{first}}" />
Hi, I'm Dan
No, you're Jim
Bi-directional Binding
=
$scope.person={name:'Dan'};
Two-way binding created
scope: { customer: '=' }
Directive
= isolate scope property
<my-directive customer="person" />
Call me back at: 123-1234
Calling 123-1234
Function Callback
&
$scope.click=function() { };
Can invoke external function
scope: { action: '&' }
Directive
& isolate scope property
<my-directive action="click()" />
@ Bind a local scope property to the value of a DOM attribute. The result
is always a string.
scope: { name: '@' }  <my-directive name="{{name}}" />
= Creates a bi-directional binding between a local scope property and the
parent scope property.
scope: { customer: '=' }  <my-directive
customer="person" />
& Execute an expression/function in the context of the parent scope.
scope: { click: '&' }  <my-directive click="click()" />
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Examples
angular.module('directivesModule')
.directive('domDirective', function () {
return {
restrict: 'A',
link: function ($scope, element, attrs) {
element.bind('click', function () {
element.html('You clicked me!');
});
element.bind('mouseenter', function () {
element.css('background-color', 'yellow');
});
element.bind('mouseleave', function () {
element.css('background-color', 'white');
});
}
};
});
<div dom-directive>Click Me!</div>
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Directive Examples
angular.module('directivesModule')
.directive('isolateScopeWithController', function () {
return {
restrict: 'EA',
scope: {datasource: '=', add: '&'},
controller: function ($scope) {
function init() {
$scope.customers = angular.copy($scope.datasource);
}
init();
$scope.addCustomer = function () {
//Call external scope's function
$scope.add();
//Add new customer to directive scope
$scope.customers.push({ … });
};
},
template: '<button ng-click="addCustomer()">Change Data</button><ul>' +
'<li ng-repeat="cust in customers">{{ cust.name }}</li></ul>'
};
}); <div isolate-scope-with-controller></div>
Transclusion
Inclusion of a document or part of a document
into another document by reference
http://en.wikipedia.org/wiki/Transclusion
<html>
<body>
</body>
</html>
<div>
Hello!
</div>
myDirective
<div class="container">
Content provided by consumer of
directive
</div>
myDirective
<div class="container" ng-transclude>
Content provided by consumer
of directive
</div>
<html>
<body>
<my-directive>
</my-directive>
</body>
</html>
<div>
Hello!
</div>
<div class="container">
<div>
Hello
</div>
</div>
Agenda
• The Role of Directives
• Peeking Under the Hood
• Shared vs. Isolate Scope
• Linking to the DOM
• Controller Love
• Directive Examples
https://github.com/DanWahlin/CustomerManagerStandard
Find more ngularJS content at:
Blog
http://weblogs.asp.net/dwahlin
Twitter
@DanWahlin
If you read this far you deserve a bigger discount!
Get 60% 70% off the video course!
http://tinyurl.com/ngDirectives70

Mais conteúdo relacionado

Mais procurados

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationDan Wahlin
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JSAkshay Mathur
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSSimon Guest
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish MinutesDan Wahlin
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBApaichon Punopas
 

Mais procurados (20)

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
 
Angular js
Angular jsAngular js
Angular js
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
Angular JS
Angular JSAngular JS
Angular JS
 
Angular js
Angular jsAngular js
Angular js
 
AngularJs
AngularJsAngularJs
AngularJs
 

Destaque

AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directivesyprodev
 
Development Trends - What's New in the World of Web Development
Development Trends - What's New in the World of Web DevelopmentDevelopment Trends - What's New in the World of Web Development
Development Trends - What's New in the World of Web DevelopmentDan Wahlin
 
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsDan Wahlin
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Dan Wahlin
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorDan Wahlin
 
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Getting Started Building Windows 8 HTML/JavaScript Metro AppsGetting Started Building Windows 8 HTML/JavaScript Metro Apps
Getting Started Building Windows 8 HTML/JavaScript Metro AppsDan Wahlin
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and httpAlexe Bogdan
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSDeepu S Nath
 
Lastest Trends in Web Development
Lastest Trends in Web DevelopmentLastest Trends in Web Development
Lastest Trends in Web DevelopmentDoris Chen
 
Using jQuery Templates
Using jQuery TemplatesUsing jQuery Templates
Using jQuery TemplatesDan Wahlin
 
JavaScript Patterns to Cleanup your Code
JavaScript Patterns to Cleanup your CodeJavaScript Patterns to Cleanup your Code
JavaScript Patterns to Cleanup your CodeDan Wahlin
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced RoutingAlexe Bogdan
 
Planificación y organización de dominio
Planificación y organización de dominioPlanificación y organización de dominio
Planificación y organización de dominiolilidani103
 
Spa Architecture with Durandal and Friends
Spa Architecture with Durandal and FriendsSpa Architecture with Durandal and Friends
Spa Architecture with Durandal and FriendsJohnny Tordgeman
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS TestingEyal Vardi
 

Destaque (20)

AngularJS Custom Directives
AngularJS Custom DirectivesAngularJS Custom Directives
AngularJS Custom Directives
 
Development Trends - What's New in the World of Web Development
Development Trends - What's New in the World of Web DevelopmentDevelopment Trends - What's New in the World of Web Development
Development Trends - What's New in the World of Web Development
 
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight Applications
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and Razor
 
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Getting Started Building Windows 8 HTML/JavaScript Metro AppsGetting Started Building Windows 8 HTML/JavaScript Metro Apps
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
 
Coffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JSCoffee@DBG - Exploring Angular JS
Coffee@DBG - Exploring Angular JS
 
Top 13 Web Development Trends And Predictions For 2015
Top 13 Web Development Trends And Predictions For 2015Top 13 Web Development Trends And Predictions For 2015
Top 13 Web Development Trends And Predictions For 2015
 
Lastest Trends in Web Development
Lastest Trends in Web DevelopmentLastest Trends in Web Development
Lastest Trends in Web Development
 
AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014
 
Using jQuery Templates
Using jQuery TemplatesUsing jQuery Templates
Using jQuery Templates
 
JavaScript Patterns to Cleanup your Code
JavaScript Patterns to Cleanup your CodeJavaScript Patterns to Cleanup your Code
JavaScript Patterns to Cleanup your Code
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
Planificación y organización de dominio
Planificación y organización de dominioPlanificación y organización de dominio
Planificación y organización de dominio
 
Spa Architecture with Durandal and Friends
Spa Architecture with Durandal and FriendsSpa Architecture with Durandal and Friends
Spa Architecture with Durandal and Friends
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
 
AngularJS
AngularJSAngularJS
AngularJS
 
Nodejs
NodejsNodejs
Nodejs
 

Semelhante a Building AngularJS Custom Directives

Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript FrameworkAll Things Open
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjsgdgvietnam
 
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014FalafelSoftware
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Opinionated AngularJS
Opinionated AngularJSOpinionated AngularJS
Opinionated AngularJSprabhutech
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoFuture Insights
 

Semelhante a Building AngularJS Custom Directives (20)

AngularJS
AngularJSAngularJS
AngularJS
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
 
Angular
AngularAngular
Angular
 
Angular
AngularAngular
Angular
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript Framework
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
 
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to Angular
Introduction to AngularIntroduction to Angular
Introduction to Angular
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Opinionated AngularJS
Opinionated AngularJSOpinionated AngularJS
Opinionated AngularJS
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
 
Quick Start to AngularJS
Quick Start to AngularJSQuick Start to AngularJS
Quick Start to AngularJS
 
Valentine with AngularJS
Valentine with AngularJSValentine with AngularJS
Valentine with AngularJS
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Building AngularJS Custom Directives

  • 3. Get 60% off the video course! http://tinyurl.com/ngDirectives60
  • 5. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Directive Examples
  • 6. Key AngularJS Directives Application • ng-app • ng-controller Forms • ng-maxlength • ng-minlength • ng-pattern • ng-required • ng-submit Templates • ng-disabled • ng-cloak • ng-hide • ng-if • ng-repeat • ng-show • ng-switch • ng-view Data Binding • ng-bind • ng-href • ng-init • ng-model • ng-src • ng-style Behavior • ng-blur • ng-change • ng-checked • ng-click • ng-key* • ng-mouse*
  • 7. Using AngularJS Directives • Attribute directives <span my-dir="exp"></span> • Element directives <my-dir></my-dir> • CSS class directives <span class="my-dir: exp;"></span> • Comment directives <!-- directive: my-dir exp -->
  • 8. Custom Directives Data-Driven Directives All about data, using other directives and a controller DOM-Driven Directives All about DOM Manipulation Behavior-Driven Directives All about events and behaviors
  • 9. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Directive Examples
  • 11. angular.module('moduleName') .directive('myDirective', function () { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment scope: { //@ reads the attribute string value, //= provides two-way binding, //& works with functions title: '@' }, template: '<div>{{ myVal }}</div>', templateUrl: 'mytemplate.html', controller: controller, link: function ($scope, element, attrs) { } //DOM manipulation } }); http://docs.angularjs.org/api/ng/service/$compile
  • 12. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Directive Examples
  • 15. Parent Scope Child Scope Wall Blocks Parent Scope
  • 16. Controller $scope.customers=[]; Depends on parent scope $scope.customers=[]; Directive Shared Controller $scope.customers=[]; Isolated from parent scope $scope.customers=[]; $scope.isolated = true; Directive Not Shared Shared Scope Isolate Scope
  • 17. Shared Scope Directive Example var app = angular.module('myModule', []); app.controller('Controller', ['$scope', function ($scope) { $scope.customer = { name: 'David', street: '1234 Anywhere St.' }; }]); app.directive('sharedScope', function () { return { template: 'Name: {{customer.name}} Street: {{customer.street}}' }; }); Scope is inherited <div shared-scope></div>
  • 18. Isolating Scope in Directives angular.module('myModule') .directive('isolateScope', function () { return { scope: {}, //isolate scope template: 'Name: {{customer.name}} Street: ' + '{{customer.street}}' }; }); <div isolate-scope></div> No data will display!
  • 19. Hi, I'm Dan String with one-way binding @ $scope.first='James'; Directive can access a string value scope: { name: '@' } Directive @ isolate scope property <my-directive name="{{first}}" />
  • 20. Hi, I'm Dan No, you're Jim Bi-directional Binding = $scope.person={name:'Dan'}; Two-way binding created scope: { customer: '=' } Directive = isolate scope property <my-directive customer="person" />
  • 21. Call me back at: 123-1234 Calling 123-1234 Function Callback & $scope.click=function() { }; Can invoke external function scope: { action: '&' } Directive & isolate scope property <my-directive action="click()" />
  • 22. @ Bind a local scope property to the value of a DOM attribute. The result is always a string. scope: { name: '@' }  <my-directive name="{{name}}" /> = Creates a bi-directional binding between a local scope property and the parent scope property. scope: { customer: '=' }  <my-directive customer="person" /> & Execute an expression/function in the context of the parent scope. scope: { click: '&' }  <my-directive click="click()" />
  • 23. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Examples
  • 24. angular.module('directivesModule') .directive('domDirective', function () { return { restrict: 'A', link: function ($scope, element, attrs) { element.bind('click', function () { element.html('You clicked me!'); }); element.bind('mouseenter', function () { element.css('background-color', 'yellow'); }); element.bind('mouseleave', function () { element.css('background-color', 'white'); }); } }; }); <div dom-directive>Click Me!</div>
  • 25. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Directive Examples
  • 26. angular.module('directivesModule') .directive('isolateScopeWithController', function () { return { restrict: 'EA', scope: {datasource: '=', add: '&'}, controller: function ($scope) { function init() { $scope.customers = angular.copy($scope.datasource); } init(); $scope.addCustomer = function () { //Call external scope's function $scope.add(); //Add new customer to directive scope $scope.customers.push({ … }); }; }, template: '<button ng-click="addCustomer()">Change Data</button><ul>' + '<li ng-repeat="cust in customers">{{ cust.name }}</li></ul>' }; }); <div isolate-scope-with-controller></div>
  • 27. Transclusion Inclusion of a document or part of a document into another document by reference http://en.wikipedia.org/wiki/Transclusion
  • 29. myDirective <div class="container"> Content provided by consumer of directive </div>
  • 30. myDirective <div class="container" ng-transclude> Content provided by consumer of directive </div> <html> <body> <my-directive> </my-directive> </body> </html> <div> Hello! </div> <div class="container"> <div> Hello </div> </div>
  • 31. Agenda • The Role of Directives • Peeking Under the Hood • Shared vs. Isolate Scope • Linking to the DOM • Controller Love • Directive Examples
  • 33. Find more ngularJS content at: Blog http://weblogs.asp.net/dwahlin Twitter @DanWahlin
  • 34. If you read this far you deserve a bigger discount! Get 60% 70% off the video course! http://tinyurl.com/ngDirectives70