前端 - angular中应该如何获取自定义标签的name属性?
阿神
阿神 2017-05-15 16:49:12
0
1
631
<livebit name="" age=""></livebit>

在指令的Link中获取name属性

阿神
阿神

闭关修行中......

全部回复(1)
大家讲道理

这个需要自己写 directive 了,例子:

<livebit name="" age=""></livebit>

 angular.module('MyApp').directive('livebit', [function() {
    return {
        restrict: 'E',  
        link: function (scope, elm, attrs) {
             arrts.name  //就可以拿到 name的值
             attrs.age //同上哦
        };
}]);

// restrict 的取值
     E == element(根据元素名找 livebit)
     C == class (根据类名来找 livebit)
     A == attribute (根据属性名找 livbit)
     ACE == 能找的都找

所以那 你的自定义标签可以写成大致几种:
有这种:

restrict = 'E'
<livebit name="" age=""></livebit>

这种:

    restrict = 'C'
<p class="livebit" name="" age=""></p>

还有这种:

restrict = 'C'
<p name="" age="" livebit></p>

找到元素之后 通过link回调 你就对自己的标签为所欲为了。
比如

请输入代码
  elm.appendChild(xxxxx)
  $(elm).jquery-插件xxx()
  .........
 ...........
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!