转自:https://www.cnblogs.com/best/tag/Angular/

1.

<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 函数来添加自定义的指令。

要调用自定义指令,HTML 元素上需要添加自定义指令名。

使用驼峰法来命名一个指令, runoobDirective, 但在使用它时需要以 - 分割, runoob-directive:

posted on 2018-01-02 10:44  Sharpest  阅读(136)  评论(0编辑  收藏  举报