AngularJS自定义指令之可选参数replace

发现这个可选参数就是闲的蛋疼!!!
不多说,看代码

可选参数:replace
默认为false,可以设置为true
若设置为true,dom中显示为:

<h3>Hello World</h3>

这里写图片描述

若设置为false

<ts-hello>
    <h3>Hello World</h3>
</ts-hello>

这里写图片描述

<!DOCTYPE html>
<html ng-app='myApp'>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body ng-controller='firstCtrl'>

        <ts-hello>
            11
        </ts-hello>

        <script src='js/angular.js'></script>
        <script>
            var app = angular.module('myApp',['ng']);
            app.controller('firstCtrl',['$scope',function($scope){

            }]);
            app.directive('tsHello',function(){
                return {
                    template:'<h3>Hello World</h3>',
                    restrict:'ECAM',
                    replace:true
                }
            });
        </script>
    </body>
</html>
posted @ 2017-10-08 10:23  hefeng6500  阅读(274)  评论(0编辑  收藏  举报