AngularJS 验证无效?
AngularJS validations not working?
我是 AngularJS 的新手,我刚刚开始调整它附带的验证,但由于某种原因我无法让它们工作:
<div class="row">
<div class="col-xs-6">
<h2>Login</h2>
<p class="text-danger">{{message}}</p>
<form name="form" novalidate>
<label>Email: </label>
<input type="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>
</div>
</div>
我给表格命名并把 novalidate
也放了。然后我尝试根据需要输入电子邮件,但将属性放在那里。但是表单仍然提交并且 AngularJS 不会阻止它提交或显示任何警告。我错过了什么?
如果您想将其设为可选,请从电子邮件输入中删除 required
属性。
<input type="email" ng-model="credentials.email" placeholder="Email" class="form-control"/>
如果您想删除电子邮件验证,请更改字段类型。
HTML5 如果您 type="email"
总是验证电子邮件
<input type="text" ng-model="credentials.email" placeholder="Email" class="form-control"/>
为您的输入提供名称字段
<form name="form" novalidate>
<label>Email: </label>
<input type="email" name="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-disabled="form.$invalid" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>
这里是 plunker :-)
http://plnkr.co/edit/pAA2wBp8zgIZV6QLwO7S?p=preview
我是 AngularJS 的新手,我刚刚开始调整它附带的验证,但由于某种原因我无法让它们工作:
<div class="row">
<div class="col-xs-6">
<h2>Login</h2>
<p class="text-danger">{{message}}</p>
<form name="form" novalidate>
<label>Email: </label>
<input type="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>
</div>
</div>
我给表格命名并把 novalidate
也放了。然后我尝试根据需要输入电子邮件,但将属性放在那里。但是表单仍然提交并且 AngularJS 不会阻止它提交或显示任何警告。我错过了什么?
如果您想将其设为可选,请从电子邮件输入中删除 required
属性。
<input type="email" ng-model="credentials.email" placeholder="Email" class="form-control"/>
如果您想删除电子邮件验证,请更改字段类型。
HTML5 如果您 type="email"
<input type="text" ng-model="credentials.email" placeholder="Email" class="form-control"/>
为您的输入提供名称字段
<form name="form" novalidate>
<label>Email: </label>
<input type="email" name="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-disabled="form.$invalid" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>
这里是 plunker :-) http://plnkr.co/edit/pAA2wBp8zgIZV6QLwO7S?p=preview