我想创建一个自定义输入组件并在我的表单中重用它,但我遇到了formGroup和formControlName的问题 .
// Form
<form [formGroup]='loginForm'>
<custom-input [myFormControlName]='email'></custom-input>
</form>
// CustomInput Component's Template
<input formControlName='myFormControlName'>
问题似乎是formControlName期望与FormGroup指令一起使用,因为我在子组件中使用formControlName,它找不到formControlName ..任何人都知道如何解决这个问题?
1 回答
你需要在你的子组件中实现control value accessor在这里阅读更多https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html