美文网首页
AngularJs directive自定义指令

AngularJs directive自定义指令

作者: 报告老师 | 来源:发表于2017-11-08 19:45 被阅读28次

通过dircetive方法可以自定义指令,譬如说想以下这种标签:<co></co>。可以使得浏览器可以认得出你自己做的标签。且可以把原来的模版的innerHTML都定到自定义的标签当中。使html语义化更强。下面介绍这种东西是怎么回事。

<body ng-app="t-app">

        <co></co>

<script>

var app = angular.module('t-app',[]);

app.directive('co',function(){

return {

restrict:'E',

template:'<div>hello</div>',

replace:true

};

});

</script>

<body>

restrict属性有4种,明天细说。

相关文章

网友评论

      本文标题:AngularJs directive自定义指令

      本文链接:https://www.haomeiwen.com/subject/oznymxtx.html