[英]Combine two directives together
I'd like to use the given model-data by the formControlName-directive with my own directive. 我想通过带自己的指令的formControlName指令使用给定的模型数据。
<input type="text"
formControlName="endDate"
my-directive>
Is there a way to access the formControl-value in the directive? 有没有办法访问指令中的formControl-value? In a component it's very easy using ControlValueAccessors...
在组件中,使用ControlValueAccessors非常容易...
Just create a matching input and you will get the value passed: 只需创建一个匹配的输入,您将获得传递的值:
@Directive({
selector: '[my-directive]'
})
class MyDirective {
@Input() formControlName:String;
ngOnChanges() {
console.log(this.formControlName);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.