轉自:https://www.cnblogs.com/best/tag/Angular/html
1.app
<html> <head> <meta charset="utf-8"> <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body ng-app="myApp"> <runoob-directive></runoob-directive> <script> var app = angular.module('myApp',[]); app.directive("runoobDirective",function(){ return { template:'<h1>自定義指令</h1>' }; }); </script> </body> </html>
除了 AngularJS 內置的指令外,咱們還能夠建立自定義指令。函數
你可使用 .directive 函數來添加自定義的指令。spa
要調用自定義指令,HTML 元素上須要添加自定義指令名。code
使用駝峯法來命名一個指令, runoobDirective, 但在使用它時須要以 - 分割, runoob-directive:cdn