@ -1,16 +1,14 @@
<form #form="ngForm">
<div>
年齡:<input
type="number"
name="age"
#age="ngModel"
[ngModel]="18"
min="18"
密碼:<input
type="password"
name="password"
#password="ngModel"
ngModel
pattern="[a-zA-Z]*"
/>
<ng-container *ngIf="age.touched">
<span *ngIf="age.hasError('min')">
最小年齡為 {{ age.errors?.min.min }} 歲
</span>
<ng-container *ngIf="password.touched">
<span *ngIf="password.hasError('pattern')">密碼只接受英文字母</span>
</ng-container>
</div>
</form>