Required HTML5 attribute does not work in Angular 2 project installed using CLI

I work on the Angular 2 login page, when I try to check the input field with the required HTML 5 attribute, it does not work, where, like in the quick launch project, it works fine. Can someone explain why it is not working and how to solve this problem?

Link to my code for my player In Plunker, it is checked, but it does not work in my project.

app.component.html code below

<form class="login-form">
  <input type="text" name="usrname" placeholder="Username"  required/>

  <input type="password" name="pwd" placeholder="Password"  required>
  <input type="submit">

</form>
+4
source share
2 answers

Starting with version 4.0.0, Angular automatically adds new features to the form. Change this new default behavior using:

<form ngNativeValidate>...</form>

Github : https://github.com/angular/angular/issues/15531#issuecomment-289555359

+19
     <form class="login-form" novalidate> 
    <input type="text" name="usrname" placeholder="Username" required="required"> 
<input type="password" name="pwd" placeholder="Password" required="required"> 
<button type="submit">Submit </button> 
    </form> 

novalidate , html5

<form class="login-form" >

novalidate , , novalidate, html5, , novalidate

0

Source: https://habr.com/ru/post/1673300/


All Articles