相关疑难解决方法(0)

不推荐使用 FormBuilder 组

我将我的项目迁移到 angular 11,我注意到我添加的全局验证FormBuilder.group不推荐使用以下消息:

group is deprecated: This api is not typesafe and can result in issues with Closure Compiler renaming.
Use the `FormBuilder#group` overload with `AbstractControlOptions` instead.
Run Code Online (Sandbox Code Playgroud)

所以这已被弃用:

  ingredientForm = this.fb.group({
    ingredientType: ['', Validators.required],
    ingredientFlavor: [''],
    isMultiFlavor: [''],
    ingredientBrand: [''],
    ingredientName: [''],
    imageFile: ['']
  }, {validators: [ValidateThirdNumber.validate]});
Run Code Online (Sandbox Code Playgroud)

如果没有这个validators选项,它就不是。

我的ValidateThirdNumber验证器:

class ValidateThirdNumber {
  static validate(control: AbstractControl): void {
      if (control) {
      const isMultiFlavor = control.get('isMultiFlavor')?.value;
      const ingredientFlavor = control.get('ingredientFlavor')?.value;
      const ingredientBrand = control.get('ingredientBrand')?.value;
      const ingredientName …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-formbuilder angular-validation angular

26
推荐指数
2
解决办法
7423
查看次数