本帖最后由 angleBoBo 于 2018-12-14 16:43 编辑
正在做的Angular项目中,需要判断表单中控件的状态,是否被编辑过。对于HTML5的<input>元素可以用
指令取到控件的状态。例如:
- <input id="name" name="name" class="form-control"
- required minlength="4" appForbiddenName="bob"
- [(ngModel)]="hero.name" #name="ngModel" >
- <div *ngIf="name.invalid && (name.dirty || name.touched)"
- class="alert alert-danger">
- <div *ngIf="name.errors.required">
- Name is required.
- </div>
- <div *ngIf="name.errors.minlength">
- Name must be at least 4 characters long.
- </div>
- <div *ngIf="name.errors.forbiddenName">
- Name cannot be Bob.
- </div>
- </div>
复制代码
但是对于wijmo的组件来说(例如:WjInputDate)如何检查 dirty 和 touched的状态? |
|