我需要从formvalidation.service.ts form.component.ts向表单添加自定义验证器
myForm = this.formBuilder.group({
    name: ['', [Validators.required,]]
});
表单验证器服务.ts
passwordValidator(): ValidatorFn {
   return (control: AbstractControl): {[key: string]:any} | null => {
     const year = control.value;
     if (!/[0-9]/.test(year) || !/[A-Z]/.test(year)) {
       return { passwordPattern: true};
     }
     return null;
   }
}
我将其导入为FormValidator.passwordValidator()。它无法将此导入component.ts文件。但当static passwordValidator(): ValidatorFn {}时,它可以这样做。但我的主管建议我不要使用静态方法。