Chapter 1: Working through the directive spectrum - The Attribute Directive
by msfrisbie
HTML
<script src="https://code.angularjs.org/1.3.2/angular.min.js"></script>
<div ng-app="myApp">
<div attribute-directive="aval"
some-attr="myvalue">
</div>
</div>
JavaScript
angular.module('myApp', [])
.directive('attributeDirective',function ($log) {
return {
// restrict defaults to A
restrict: 'A',
template: '<p>An attribute directive</p>',
link: function(scope, el, attrs) {
$log.log(el.html());
// <p>An attribute directive</p>
$log.log(attrs.attributeDirective);
// aval
$log.log(attrs.someAttr);
// myvalue
}
};
});