Home > Software engineering >  Angular setting a default number value
Angular setting a default number value

Time:10-07

I don't know if this is a stupid question. But I want a input field with a type numberto have a default value 1 when the page opens. I set the value as 1 but, it didn't change anything and the input field is still empty. What should I add to fix it?

                <mat-form-field appearance="outline">
                    <mat-label>Amount</mat-label>
                    <input matInput type="number" [(ngModel)]="WorkItemSelection.CopyQuantity" name="CopyQuantity" value="1">
                </mat-form-field>

CodePudding user response:

No need for value="1". Just in your .ts do this:

ngOnInit() {
  WorkItemSelection.CopyQuantity = 1;
}
  • Related