I was going to use Plunker to assist me in testing a directive, but first I just wanted to create one to test plunker was working, so I put in some sample code. Guess what, basic directives are not working and I have no idea why.
My directives:
app.directive('attributeDirective', function() {
return {
restrict: 'A',
link: function(scope, iElement, iAttrs) {
iElement.bind('click', function() {
console.log('clicked attributeDirective');
});
iElement.bind('mouseover', function() {
iElement.css('cursor', 'pointer');
});
}
};
});
app.directive('elementDirective', function() {
return {
restrict: 'E',
replace: true,
template: '<h2>this is elementDirective</h2>',
link: function(scope, iElement, iAttrs) {
iElement.bind('click', function() {
console.log('clicked elementDirective');
});
iElement.bind('mouseover', function() {
iElement.css('cursor', 'pointer');
});
}
};
});
My html:
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<h2 attributeDirective>Here is my attribute directive</h2>
<elementDirective></elementDirective>
</body>
while calling a directive in
html
you should replacecamelcase
in directives name like this,<element-directive></element-directive>
and not as it is,<elementDirective></elementDirective>
like you did.
Hope this helps!!!
PLUNKER
see through the custom directives here