HTML必需的验证被Angular忽略了吗?

Sof*_*oun 7 html validation html-validation angular

Angular 4忽略了内置的html验证.

如何让Angular考虑输入元素的html必填字段?

期望的行为:

期望的行为

代码:

         <form #loginForm="ngForm" (ngSubmit)="login()" class="m-t" role="form" action="#">
            <div class="form-group">
                <input type="text" [(ngModel)]="username" name="username" class="form-control" 
                [placeholder]="'Nom d\'utilisateur' | translate"  required />
            </div>
            <div class="form-group">
                <input type="password" [(ngModel)]="password" name="password" class="form-control" 
                [placeholder]="'Mot de passe' | translate" required>
            </div>
            <button type="submit" data-spinner-color="white" data-style="zoom-in" 
            [ladda]="isLoading" translate class="btn btn-primary block full-width m-b">
                <span translate >Login</span>
            </button>

            <a [routerLink]="['/reset' , '1']"><small translate>Mot de passe oublié ?</small></a>
            <br><br>
            <p class="text-muted text-center">
                <small translate>vous n'êtes pas encore enregistré ?</small>
            </p>
            <a translate id="register" class="btn btn-sm btn-white btn-block" [routerLink]="['/register']">
                 Créer un compte
            </a>
        </form>
Run Code Online (Sandbox Code Playgroud)

cor*_*opy 11

我也被这种变化所困扰.它未列在角度4的突变变化列表中.

您需要添加ngNativeValidate

<form ngNativeValidate #loginForm="ngForm" (ngSubmit)="login()" class="m-t" role="form" action="#">
Run Code Online (Sandbox Code Playgroud)

根据这个评论