formations/javascript/angular/creation-directives-2.md

27 lines
546 B
Markdown
Raw Normal View History

2015-04-09 23:11:56 +02:00
# .cadoles-slide-title[Création de directives (2/4)]
- Les directives peuvent prendre la forme d'éléments, d'attributs ou de classes.
```html
<script>
angular.module('myApp', [])
.directive('myDirective', function() {
return {
//Type de la directive: 'E' : Element, 'A': Attribut, 'C': Classe (ou composition des trois)
restrict: 'E'
};
})
;
</script>
<!-- Usage -->
<!-- "E" -->
<my-directive></my-directive>
<!-- "A" -->
<div my-directive></div>
<!-- "C" -->
<div class="my-directive"></div>
```