Artikel ini menjelaskan metode AngularJS menggunakan directive custom directive untuk mengimplementasikan pewarisan atribut. Bagikan untuk referensi Anda, sebagai berikut:
1. Kode HTML:
<! Doctype html> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/</title </title> src = "../../ konten/plugin/angular/angular.min.js"> </script> </head> <body ng-app = "Mainapp" ng-controller = "mainController"> <quber-grid = "border: 1px solid #f00;"> </ber-grid> </body> </ht/ht/ht/ht #f00; "> </ber-grid> </body> </ht> ht/ht/ht/ht #f00;"> </ber-grid> </body> </ht> ht/ht> ht/ht #/ht #f00; "> </quar-grid> </body> </ht> ht> ht> ht> ht/ht #/ht>
2. File tmp.html
<Div Quber-Grid-Attr> Saya konten templat untuk tes! </div>
3. Kode JS:
//Initialize the Angular object var myNg = angular.module('mainApp', []);myNg.directive('quberGrid', function () { return { restrict: 'EA', replace: true,//Remove the <quber-grid> tag templateUrl: 'tmp.html', link: function (sco, ele, attr) { //Notify the subordinate DOM and execute the Acara bernama SendChildGridattr SCO. $ Broadcast ('SendChildGridAttr', attr); (val, obj) {if (key! = '$ attr' && key! = '$$ elemen') {// Atur atribut tag dan nilai attr. $ set (key, val); }}; }}; }); myng.controller ('MainController', function ($ scope) {});Efeknya adalah sebagai berikut:
Saya harap artikel ini akan membantu pemrograman AngularJS semua orang.