2016-03-07 24 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);