Angular validation with Required not working
The above answers are right, you just have to add ngNativeValidate
to the form tag. I would like to add that if you want the submit button to not perform the (click)
action when the form is not valid, use form.checkValidity()
<form ngNativeValidate #form >
<input type="text" required/>
<button name="submit" type="submit" (click)="form.checkValidity()? login() : null">
Sign In
</button>
</form>
@Fredrik answer is right.
Angular adds the novalidate
attribute to your forms automatically when using the template driven approach. That's why you're not prevented from submitting.
But if you want browser validation then add ngNativeValidate
attribute in your form.
<form ngNativeValidate>
<input type='text' name='projectName' [(ngModel)]='projectName' required >
<input type='submit' value='submit' />
<form>