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

后端 未结 9 1661
野的像风
野的像风 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:47

    in component:

    formData.form.controls['email'].setErrors({'incorrect': true});
    

    and in HTML:

    
    
    {{email.errors| json}}

提交回复
热议问题