如何在表单组模型中显式添加验证?

时间:2018-06-10 08:11:16

标签: angular6 angular-forms angular-validation

我正在学习angular6让我说我的用户模型如下。

我的用户模型如下所示

export class Report{

 constructor(){
   this.isActive = true;
   this.createdAt = new Date();
 }

 id ?: string;
 name = "";
 custom_label_1 = "";
 custom_label_2 = "";
 custom_label_3 = "";
 addresses: Address[];
 createdAt ?: any;
 updatedAt ?: any;
 isActive ?: boolean;
}

在组件中,我的表单定义如下所示

this.user = new User() this.userForm = this.fb.group(this.user);

现在我想明确地在用户模型中添加验证器而不是

  

this.fb.group({“name”:[“”,[Validators.requires]]})

我该如何添加验证?

0 个答案:

没有答案