我有一个指令来决定是否需要输入,蒙面,等等.我遇到了需要向其添加一个新指令的情况:基本上,这个新指令将掩码特性添加到输入中。
<input type="text" formInput [rules]="rules" [(ngModel)]="value" />这是formInput指令:
export class DefaultFormInputDirective {
@Input() private rules;
private el: ElementRef;
constructor(el: ElementRef) {
this.el = el;
}
ngOnInit() {
this.defineRules();
}
defineRules() {
if(this.rules == undefined) {
return;
}
if(this.rules.indexOf('required') != -1) {
this.el.nativeElement.required = true;
}
if(this.rules.indexOf('numeric') != -1) {
// Here is where I need to add currencyMask directive
}
}
}发布于 2017-03-30 20:17:42
发布于 2017-03-30 20:14:34
不支持动态添加指令。只能动态添加/删除组件。
https://stackoverflow.com/questions/43127013
复制相似问题