Here is my component in Angular 4:
@Component( {
selector: \'input-extra-field\',
template: `
I was facing this error while running Karma Unit Test cases Adding MatSelectModule in the imports fixes the issue
imports: [
HttpClientTestingModule,
FormsModule,
MatTableModule,
MatSelectModule,
NoopAnimationsModule
],
I had the same problem and the issue was that my child component had an @input
named formControl
.
So I just needed to change from:
<my-component [formControl]="formControl"><my-component/>
to:
<my-component [control]="control"><my-component/>
ts:
@Input()
control:FormControl;
I had this same error- I accidentally binded [(ngModel)] to my mat-form-field
instead of the input
element.
This is kind of stupid, but I got this error message by accidentally using [formControl]
instead of [formGroup]
. See here:
WRONG
@Component({
selector: 'app-application-purpose',
template: `
<div [formControl]="formGroup"> <!-- '[formControl]' IS THE WRONG ATTRIBUTE -->
<input formControlName="formGroupProperty" />
</div>
`
})
export class MyComponent implements OnInit {
formGroup: FormGroup
constructor(
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.formGroup = this.formBuilder.group({
formGroupProperty: ''
})
}
}
RIGHT
@Component({
selector: 'app-application-purpose',
template: `
<div [formGroup]="formGroup"> <!-- '[formGroup]' IS THE RIGHT ATTRIBUTE -->
<input formControlName="formGroupProperty" />
</div>
`
})
export class MyComponent implements OnInit {
formGroup: FormGroup
constructor(
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.formGroup = this.formBuilder.group({
formGroupProperty: ''
})
}
}
In my case i used directive, but hadn't imported it in my module.ts file. Import fixed it.
#Background
In my case, the error was triggered by changing element tag from to by fault. Inside <TextView an [(ngModel)]="name". was defined.
After removing [(ngModel)]="name" error was gone.