I have the following code
<form #createForm="ngForm">
<mat-form-field>
<mat-select placeholder="Favorite food"
matInput
[ngModel]
food="food"
#food="ngModel" required>
<mat-option *ngFor="let food of foods" [value]="food.value">
{{ food.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</form>
<button [disabled]="!createForm.valid">submit</button>
Since I want the "selection" is a required field, the "submit" button should be disabled when the form is rendered. However, the "submit" button is enabled when the form is displayed. What is the problem?
<form #myForm="ngForm"> <mat-select name="journal_bank_id" placeholder="Bank Account" [(ngModel)]="journal.journal_bank_id" required><mat-option>--</mat-option><mat-option *ngFor="let bank of bank_accounts | async" [value]="bank.bank_id">{{bank.bank_account_number }}</mat-option></mat-select><button mat-raised-button type="submit" color="primary" (click)="save()" [disabled]='myForm.invalid'>Save</button>
– Mayan