Last active
April 18, 2018 19:15
-
-
Save rishabhgupta/d07fcd24cb4a9e5df7a7081d808ba618 to your computer and use it in GitHub Desktop.
Directives in Angular JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true, | |
scope: { | |
studentName: "@", // Symbol for creating a text hole | |
studentObject: "=", // Symbol for object hole | |
studentFunction: "&", // Symbol for function hole | |
}, | |
compile: function(elem, attrs){ | |
console.log(elem); | |
return { | |
post: function(scope, elements, attrs){ | |
if (scope.studentObject.name === ""){ | |
elements.removeAttr('class'); | |
} | |
}; | |
}; | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-->directives | |
-->searchResult | |
-->searchResult.directive.js | |
-->searchResult.tpl.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Results</h1> | |
<searchResults></searchResults> | |
<searchResults></searchResults> | |
<searchResults></searchResults> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true, | |
scope: { | |
// This is now the model for our directive | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true, | |
scope: { | |
studentName: "@", // Symbol for creating a text hole | |
studentObject: "=", // Symbol for object hole | |
studentFunction: "&", // Symbol for function hole | |
}, | |
link: function(scope, elements, attrs){ | |
if (scope.studentObject.name === ""){ | |
elements.removeAttr('class'); | |
} | |
}; | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
temlate: '<div><h3>name</h3><p>Description</p><p>Address</p></div>', | |
replace: true | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: 'AECM', | |
temlate: '<div><h3>name</h3><p>Description</p><p>Address</p></div>', | |
replace: true | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
temlate: '<div><h3>name</h3><p>Description</p><p>Address</p></div>' | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<search-result | |
student-name={{student.name}} | |
student-object="student" | |
student-function="studentFunction(param)"> | |
</search-result> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true, | |
scope: { | |
studentName: "@", // Symbol for creating a text hole | |
studentObject: "=", // Symbol for object hole | |
studentFunction: "&", // Symbol for function hole | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<search-result | |
student-name={{student.name}} | |
student-object="student" | |
student-function="studentFunction(param)"> | |
<p>*Terms and Conditions Apply.</p> | |
</search-result> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myapp.directive("searchResult",function(){ | |
return { | |
restrict: "AECM", | |
temlateUrl: "directives/searchResult.tpl.html", | |
replace: true, | |
scope: { | |
studentName: "@", // Symbol for creating a text hole | |
studentObject: "=", // Symbol for object hole | |
studentFunction: "&", // Symbol for function hole | |
}, | |
transclude: true | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is wrong, it is standard for JS - camel case - but not for html--> | |
<searchResult someAttribute="#"></searchResult> | |
<!-- This is correct --> | |
<search-result some-attribute="#"></search-result> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Results</h1> | |
<div> | |
<h3>name</h3> | |
<p>Description</p> | |
<p>Address</p> | |
</div> | |
<div> | |
<h3>name</h3> | |
<p>Description</p> | |
<p>Address</p> | |
</div> | |
<div> | |
<h3>name</h3> | |
<p>Description</p> | |
<p>Address</p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment