[英]adding element to parent from directive
为了禁用表格中的chrome自动完成功能,我想创建一个angular指令,该指令添加虚拟输入元素,我的代码是`angular.module(“ noc.components”)。directive('customInput',function($ compile){ “使用严格”;
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不是-我希望它位于指令上方,我该怎么办?
我最终能够解决自己的问题:
我将其更改为elem.parent().prepend(el);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.