2016-03-07 67 views
0
向父代添加元素

为了禁用表单中的自动完成chrome,我想创建添加虚拟输入元素的角度指令 我的代码是 `angular.module(“noc.components”)。directive ( 'customInput',函数($编译){ “使用严格”;从指令

return { 
    restrict:'E', 
    template:'<input>', 
    replace:true, 
    link: function(scope, elem) { 
     //scope.type = attrs.type || 'email'; 
     var el = angular.element('<input name={{type}} style="display: none">'); 
     //var type = elem[0].name; 
     $compile(el)(scope); 
     elem.parent().append(el); 
    } 
}; 

});`

和HTML是

<div class="form-group"> 
           <label for="setupWizardUserStepEmail">Email Address</label> 
           <custom-input class="form-control" 
             id="setupWizardUserStepEmail" 
             ng-model="setupRequest.userRequest.email" 
             name="email" 
             ng-required="true" 
             noc-validation="email" 
             autocomplete="off" 
             autofocus="true"> 
          </div> 

但是,注入的html不是在父 - 我希望它是在指令 以上我怎么能做到这一点?

回答

0

我能解决到底我自己的问题:

我改成了elem.parent().prepend(el);