Simple Directives
by gogirl
HTML
<body ng-app="mydirectives">
<div m-d>I am a div element. Click on any three element to get element type alerted:</div>
<button m-d>Click me</button>
<button m-d>And me</button>
<div m-d2>I am a div element. Click on any three element to get element type alerted:</div>
<button m-d2>Click me</button>
<button m-d2>And me</button>
</body>
JavaScript
angular.module('mydirectives', ['mydirectives.mD', 'mydirectives.mD2']);
angular.module('mydirectives.mD', []).directive("mD", function () {
return {
restrict: 'A',
link: function (scope, iElem, iAttrs) {
iElem.bind("click", function () {
alert(iElem);
});
}
}
});
angular.module('mydirectives.mD2', []).directive("mD2", function () {
return {
restrict: 'A',
link: function (scope, iElem, iAttrs) {
iElem.bind("click", function () {
alert(iElem);
});
}
}
});