Skip to content

Instantly share code, notes, and snippets.

@jfreyre
Created March 31, 2015 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfreyre/337b64a96b69750bb25b to your computer and use it in GitHub Desktop.
Save jfreyre/337b64a96b69750bb25b to your computer and use it in GitHub Desktop.
Angular | Same directive name but different implementation
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example14-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.6/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="multipleDirective">
<my-directive></my-directive>
<div my-directive></div>
<div class="my-directive"></div>
</body>
</html>
(function(angular) {
'use strict';
angular.module('multipleDirective', [])
.directive('myDirective', function() {
return {
restrict: 'E',
template: 'Hey! I am a directive restricted to element'
};
})
.directive('myDirective', function() {
return {
restrict: 'A',
template: 'Hey! I am a directive restricted to attribute'
};
})
.directive('myDirective', function() {
return {
restrict: 'C',
template: 'Hey! I am a directive restricted to class'
};
});
})(window.angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment