Angular 4 remove required validator conditionally

后端 未结 10 1941
[愿得一人]
[愿得一人] 2021-02-01 01:26

In Angular 4 app I have a form model like this:

this.form = this._fb.group({
    title: [\'\', [Validators.required, Validators.minLength(3), Validators.maxLengt         


        
10条回答
  •  悲哀的现实
    2021-02-01 02:10

    you can use this to clear validation from reactive form

    this.form.controls['title'].clearValidators(); this.form.controls['title'].updateValueAndValidity();

    you can use this to add validation in reactive form

    this.form.controls['title'].setValidators([Validators.required]); this.form.controls['title'].updateValueAndValidity();

提交回复
热议问题