How to fix ngModel cannot be used to register form controls with a parent formGroup directive

If we use FormGroup then don’t use [(ngModel)].

If you want to use the both then as you have getting erro**r,

use [ngModelOptions]="{standalone: true}" solve the problem.

<input [(ngModel)]="itemList" [ngModelOptions]="{standalone: true}">

**Error Type

core.js:4197 ERROR Error:
ngModel cannot be used to register form controls with a parent formGroup directive. Try using
formGroup's partner directive "formControlName" instead. Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
<input [(ngModel)]="showMoreControls" [ngModelOptions]="{standalone: true}">
</div>
at Function.modelParentException (forms.js:4691)
at NgModel._checkParentType (forms.js:5050)
at NgModel._checkForErrors (forms.js:5040)
at NgModel.ngOnChanges (forms.js:4961)
at NgModel.rememberChangeHistoryAndInvokeOnChangesHook (core.js:2131)
at callHook (core.js:3042)
at callHooks (core.js:3008)
at executeInitAndCheckHooks (core.js:2960)
at selectIndexInternal (core.js:6179)
at Module.ɵɵadvance (core.js:6152)

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments