Form validation is not working in angular?

前端 未结 3 1261
生来不讨喜
生来不讨喜 2020-12-21 23:00

I want to check whether the dropdown is empty.

Need to show the required message and

If not empty, enable the submit button.

If empty, disable the

3条回答
  •  误落风尘
    2020-12-21 23:55

    To make the submit button disabled (link)

    
    

    In order to check whether the dropdown is empty or not, you need to make the form fields required like

    this.myForm = this.formBuilder.group({
      'name': [this.name, Validators.required],
      'symbol': [this.symbol, [Validators.required]]
    });
    

    Inorder to show the error highlight you need to add an ngClass in the templete like.

    [ngClass]="{'error': myForm.controls.name.valid == false}"
    

提交回复
热议问题