search

Home  >  Q&A  >  body text

Front-end - How to get the name attribute of a custom tag in angular?

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

Get the name attribute in the link of the command

阿神阿神2760 days ago679

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 16:51:12

    You need to write your own directive for this, example:

    <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 == 能找的都找
    

    So your custom tag can be written in the following ways:
    There is this:

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

    This kind:

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

    There is also this:

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

    After finding the element, you can do whatever you want with your label through the link callback.
    For example

    请输入代码
      elm.appendChild(xxxxx)
      $(elm).jquery-插件xxx()
      .........
     ...........
    

    reply
    0
  • Cancelreply