I have two input
where I need to use [ngModelOptions]="{standalone: true}"
to avoid the warning:
It looks like you're using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in Angular v7.
So in this one it works correctly:
<form>
[...]
<div>
<mat-label>myLabel</mat-label>
<input class="inputText" matInput type="text" [(ngModel)]="totaleAttivita" [readonly]="true" [ngModelOptions]="{standalone: true}">
</div>
[...]
</form>
but for this other one it says " can't bind to ngModelOptions since it isn't a known property of 'input' "
:
<form [formGroup]="myForm">
<mat-form-field class="col" >
<input ngModel #pickerDal matInput [matDatepicker]="pickerDal"
(dateChange)="fromDate('change', $event)" formControlName="dal" [(ngModel)]="dal_default"
(focus)="pickerDal.open()" readonly **//WANT TO PUT STANDALONE:TRUE HERE**>
<mat-datepicker-toggle matSuffix [for]="pickerDal"></mat-datepicker-toggle>
<mat-datepicker #pickerDal></mat-datepicker>
</mat-form-field>
[...]
</form>
EDIT
I did a mistake and believed the warning came from the wrong input. I've fixed the question with the correct example. Now the input
s are basically the same, the only difference is that they are in a different component.
I've imported FormsModule in my app.component. In fact the first input works fine with ngModelOptions.
<form [formGroup]="form">
your need add [ngModelOptions]="{standalone: true}" in this input tag (this become like<input [(ngModel)]="variable" [ngModelOptions]="{standalone: true}">
. This is util, e.g. if you want has a checkbox that not belong to the formGroup, but change the aparence of the form or the value of one formControl that belong to the form but has not input. Of course is depreciated (and has no sense) use [formControl] or formControlName and [(ngModel)] in the same input tag – Eliseo