Angular响应式表单中的自定义表单级验证器和updateOn选项为'blur”不起作用
创始人
2024-10-30 08:00:40
0
  1. 在组件中定义自定义表单级验证器,并在控件初始化时将其添加到FormGroup中。
import { Component } from '@angular/core';
import { FormControl, FormGroup, ValidatorFn, AbstractControl } from '@angular/forms';

@Component({
  selector: 'my-app',
  template: `
    
` }) export class AppComponent { formGroup: FormGroup; constructor() { const nameValidator: ValidatorFn = (control: AbstractControl): {[key: string]: any} | null => { const value = control.value; const invalid = value && value.length < 5; return invalid ? {'nameInvalid': {value}} : null; }; this.formGroup = new FormGroup({ name: new FormControl('', { validators: nameValidator, updateOn: 'blur' }) }); } }
  1. 在模板中绑定控件的错误提示信息。
Name must be at least 5 characters long

相关内容

热门资讯

透视ai!pokemmo脚本,... 透视ai!pokemmo脚本,约局吧如何查看是否有挂,攻略教程(有挂教程)1、许多玩家不知道约局吧如...
透视科技!德普之星有辅助软件吗... 透视科技!德普之星有辅助软件吗,(德普)确实真的有挂,科技教程(有挂工具);1、该软件可以轻松地帮助...
透视存在“pokerworld... 透视存在“pokerworld辅助器”透视辅助机制(确实真的有挂)1、下载好pokerworld辅助...
透视科技!德普之星有辅助软件吗... 透视科技!德普之星有辅助软件吗,(德普)本来有挂,辅助教程(有挂详情);1、下载好德普之星有辅助软件...
透视最新“拱趴大菠萝有什么挂”... 透视最新“拱趴大菠萝有什么挂”透视辅助器(总是真的有挂);1、超多福利:超高返利,海量正版游戏,拱趴...
透视新版!德普软件,(德普之星... 透视新版!德普软件,(德普之星)好像是有挂,曝光教程(有挂解说);1)德普软件辅助挂:进一步探索德普...
透视好友房“xpoker怎么作... 透视好友房“xpoker怎么作弊”透视辅助神器(总是存在有挂)xpoker怎么作弊辅助器中分为三种模...
透视脚本!如何下载德普之星辅助... 透视脚本!如何下载德普之星辅助软件,德普之星怎么设置埋牌,高科技教程(有挂工具)1、进入到如何下载德...
透视辅助“sohoo竞技联盟辅... 透视辅助“sohoo竞技联盟辅助器”透视辅助黑科技(其实真的是有挂)1、超多福利:超高返利,海量正版...
透视挂!德普之星的辅助工具介绍... 透视挂!德普之星的辅助工具介绍,(德扑之心)原来有挂,可靠技巧(有挂黑科技)德普之星的辅助工具介绍辅...