Angular 4 remove required validator conditionally

Source: https://stackoverflow.com/questions/46488078/angular-4-remove-required-validator-conditionally

if you want to add validation try this one.
saveDraft() {
   this.form.get('title').setValidators([Validators.required, Validators.minLength(3)]);
   this.form.get('title').updateValueAndValidity();
}
if you want to remove validators try this one.
saveDraft() {
 this.form.get('title').clearValidators();
 this.form.get('title').updateValueAndValidity();
}

Không có nhận xét nào:

StaticImage

  import React , { useEffect , useRef } from "react" import { StaticImage } from "gatsby-plugin-image" impor...