Cet article décrit la méthode d'AngularJS en utilisant des directives personnalisées directives pour implémenter l'héritage des attributs. Partagez-le pour votre référence, comme suit:
1. Code HTML:
<! Doctype html> <html xmlns = "http://www.w3.org/1999/xhtml"> <éad> <meta http-equiv = "contenu-type" contenu = "Text / html; charset = utf-8" /> <title> </ title> <script> <script src = "../../ contenu / plugins / angular / angular.min.js"> </ script> </ head> <body ng -pp = "mainApp" ng-controller = "MainController"> <Quber-Grid Style = "Border: 1px Solid # f00;"> </bber-grid> </odody> </html>
2. Fichier tmp.html
<Div Quber-Grid-ATTR> Je suis le contenu du modèle pour le test! </div>
3. Code JS:
// initialiser l'objet angulaire var myng = angular.module ('mainApp', []); myng.directive ('QuberGrid', function () {return {restrict: 'ea', remplacer: true, Événement nommé SendChildgridattr SCO. $ Broadcast ('SendChildgridattr', att);}};}); Myng.Directive ('QuberGridattr', Function () {return {restrict: 'a', link: function (sco, ele, data) {SCO. (Val, Key, OBJ) {if (Key! = '$ att' && KEY! = '$$ Élément') {// Définit les attributs de balise et les valeurs att. }}; }}; }); Myng.Controller ('MainController', fonction ($ Scope) {});Les effets sont les suivants:
J'espère que cet article sera utile à la programmation AngularJS de tous.