How can I manually set an Angular form field as invalid?

后端 未结 9 1645
野的像风
野的像风 2020-11-28 01:58

I am working on a login form and if the user enters invalid credentials we want to mark both the email and password fields as invalid and display a message that says the log

9条回答
  •  遥遥无期
    2020-11-28 02:23

    Though its late but following solution worked form me.

        let control = this.registerForm.controls['controlName'];
        control.setErrors({backend: {someProp: "Invalid Data"}});
        let message = control.errors['backend'].someProp;
    

提交回复
热议问题