標籤:app arp utf-8 script angularjs turn ret oct ext
index.html:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"></head><body><div ng-app="myApp"> <custom-tags>122</custom-tags> <div class="custom-tags"> </div> <div custom-tags> </div> <!--directive:custom-tags--></div><script type="text/javascript" src="../../vendor/angular/angularJs.js"></script><script type="text/javascript" src="app/index.js"></script><script></script></body></html>
index.js:
var myApp = angular.module(‘myApp‘, [],[‘$compileProvider‘,function ($compileProvider) { $compileProvider.directive(‘customTags‘,function () { return { //E:element C:class屬性 A:attribute M:代表注釋 restrict:"ECAM",//限制約束條件 //替換 template:‘<div>custom-tags-html</div>‘, replace:true //如果此配置為true則替換指令所在的元素 如果為false或者不指定 則把當前指令追加到所在元素的內部 } })}])
運行結果:
angularJS1筆記-(9)-自訂指令(restrict/template/replace)