1
比方说,我有一个指令,看起来像这样:添加类transcluded元素
<input class="icon-input" type="text">
我想这结束了:
<div class="col-xs-12">
<i ng-class="icon"></i>
<input class="icon-input" type="text" class="form-control">
</div>
(以上钍显著的部分是class="form-control"
)
我的指令目前看起来是这样的:
'use strict';
class IconInput {
constructor() {
this.restrict = 'C';
this.replace = true;
this.transclude = 'element';
this.templateUrl = 'app/form-fields/icon-input/icon-input.html';
this.scope = { icon: '@' }
}
}
export default IconInput;
如何将class="form-control"
添加到我包含的input
元素中?
您应该只输入输入,并从外部传递类,int输入定义。 – Fals
你是什么意思“仅输入输入”?我认为那就是我所做的。 –
你正在做的方式,一切都被模板替换。如果使用ng-transclude作为模板的一部分,它将替换原始输入+模板的其余部分。 – Fals