i'm learning how to use Angular Directives to manipulate my HTML. And i have some doubts about it.
I have my hideElementDirective:
var hideElementDirective = function() {
var hideElement = {
init: function(element) {
element.css('display', 'none');
}
}
return {
link: function($scope, $element) {
hideElement.init($element);
}
}
}
angular.module('app').directive('hideElementDirective', hideElementDirective);
Call in the HTML:
<hide-element-directive> This tag will disappear </hide-element-directive>
Everything perfect.
Lets increase the logic. I have this indicator that will toggle the state of the hide-element-directive, how should i name the indicator, and how should i catch in the directive?
Example:
<hide-element-directive> This tag will hide/show if you click in the indicator element that </hide-element-directive>
indicator element: <button> If you click me i will hide/show the hide-element-directive </button>
There is any convetion for that? Should i use data-* or insert a class name related like class="hide-element-directive-indicator"
Thanks.
transcludethe element you want to hide and use a template in directive defenition for making a button as an indicator