angular的formGroup的校验触发
作者:互联网
angular material 中form表单提交时赋值,无法触发input输入框的样式
onSubmit() { Object.values(this.formGroup.controls).forEach(i=>{ i.marksAsDirty(); }) this.formGroup.patchValue(this.formGroup.getRowValue()) if(this.formGroup.invalid){ return; } }
// 需要在app.module.ts 中添加
import { errorStateMatcher, showOnDirtyErrorStateMatcher } from '@angular/material' providers: [ { provide: errorStateMatcher, useClass: showOnDirtyErrorStateMatcher } ],
标签:触发,errorStateMatcher,material,校验,showOnDirtyErrorStateMatcher,formGroup,angular 来源: https://www.cnblogs.com/lskzj/p/11444937.html