Angular 模板验证表单 [英] Angular template validation form
问题描述
我正在处理表单验证.我正在使用模板驱动的验证表单,其编码如下.它现在工作正常,但是当我尝试在输入中添加 #username = "ngModel" 和 #password = "ngModel
" 以创建验证类时,它显示了一个错误.也请找出错误.
<div class="row"><div class="居中文本中心"><div class="login-cont col-md-4 col-md-offset-4 vcenter"><form id="login_form" name="login-form" #f="ngForm" role="form" (ngSubmit)="f.form.valid && login()" novalidate><input id="username" [(ngModel)]="username" name="username" required class="form-control" type="text" placeholder="Username" ><input id="userPassword" class="form-control" required type="password" name="userPassword" required placeholder="Password" [(ngModel)]="password" ><button type="submit" class="btn login-btn">登录</button></表单>
<小时>
不能赋值给引用或变量!在 _AstToIrVisitor.visitPropertyWrite (webpack-internal:///../../../compiler/esm5/compiler.js:26226:23)在 PropertyWrite.visit (webpack-internal:///../../../compiler/esm5/compiler.js:4803:24)在 convertActionBinding (webpack-internal:///../../../compiler/esm5/compiler.js:25676:45)在 eval (webpack-internal:///../../../compiler/esm5/compiler.js:28166:22)在 Array.forEach (<匿名>)在 ViewBuilder._createElementHandleEventFn (webpack-internal:///../../../compiler/esm5/compiler.js:28162:18)在节点.(匿名函数)(webpack-internal:///../../../compiler/esm5/compiler.js:27581:27)在 eval (webpack-internal:///../../../compiler/esm5/compiler.js:28107:22)在 Array.map (<匿名>)在 ViewBuilder._createNodeExpressions (webpack-internal:///../../../compiler/esm5/compiler.js:28106:56)
<小时>
这是我尝试过的,但它给了我一个错误
<input id="username" class="form-control" type="text" required name="username" placeholder="Username" [(ngModel)]="username" minlength="4" #names="ngModel"><div *ngIf="names.invalid && (names.dirty || names.touched)"class="警报警报-危险">