Lui*_*mas 2 angular2-forms angular2-formbuilder angular angular2-form-validation ignite-ui-angular
我已经知道inputa 中的项目FormControl可以被标记dirt或touched通过调用以下任何方法(也许更多): group.markAsTouched(); form.get('control-name').markAsTouched(); form.markAllAsTouched(); form.controls[someIndex].markAsTouched();
但是,我可以看到该markAsTouched方法似乎在输入focus为 then时被调用blur。
有没有办法通过代码达到相同的结果?比方说,当点击一个按钮时。
在这里,您可以看到当前标准行为的 gif,无需表单,您也可以在以下实时示例中自行测试:
https://stackblitz.com/edit/angular-peq11f
对我来说,很明显这种行为应该可以由代码触发,而不仅仅是在blur事件触发时触发
像这样的东西:
<input #myInput>
<button (click)="myInput.markAsTouched()">click</button>
Run Code Online (Sandbox Code Playgroud)
您可以使用独特的 formControl<input [formControl]="control">和markAsTouched
<input [formControl]="control">
<button (click)="control.markAsTouched()">click</button>
{{control.touched}}
Run Code Online (Sandbox Code Playgroud)
你在哪里有.ts
// as a property
control = new FormControl();
// or in a function
this.control.markAsTouched();
Run Code Online (Sandbox Code Playgroud)
AFormControl可以属于 a FormGroup,也可以不属于 a。而且,没有必要有标签input。我们使用标签输入来更改值,但如果删除input,控件也会标记为触摸
| 归档时间: |
|
| 查看次数: |
9419 次 |
| 最近记录: |