如何在formcontrol中设置默认布尔false

问题描述 投票:0回答:3

在formcontrol(主字段)ko中将默认布尔值设置为false

this.contactForm = new FormGroup({
      name: new FormControl('', [ Validators.required]),
      contact: new FormControl('', [ Validators.required,Validators.minLength(10)]),
      email: new FormControl('', [ Validators.required,Validators.email]),
      primary: new FormControl('',[])
    });

console print img

angular angular-material ionic4 angular8 angular-forms
3个回答
0
投票

您可以在OnInit()函数中使用patchValue()

this.contactForm.patchValue({primary: false});

0
投票

您可以尝试以下方法:{ email: new FormControl({ value: '', disabled: true }, ...) }


0
投票

FormControl的第一个参数获取初始值,因此您可以轻松地编写:

new FormControl(false, [...]);

或者,如果需要,可能会更复杂:

new FormControl({ value: false, disabled: true }, [...]);
© www.soinside.com 2019 - 2024. All rights reserved.