我是棱角分明的新手.我很困惑$dirty和$invalid,他们几乎听起来一样.
原文链接:https://www.f2er.com/angularjs/141504.html电子邮件dg-model中使用的$dirty和$invalid有什么区别?以下是场景.这是W3Schools的一个例子.
<form ng-app="myApp" ng-controller="validateCtrl" name="myForm" novalidate> <p> Username:<br> <input type="text" name="user" ng-model="user" required> <span style="color: red" ng-show="myForm.user.$dirty && myForm.user.$invalid"> <span ng-show="myForm.user.$error.required">Username is required.</span> </span> </p> <p> Email:<br> <input type="email" name="emaill" ng-model="email" required> <span style="color: red" ng-show="myForm.email.$dirty && myForm.email.$invalid"> <span ng-show="myForm.email.$error.required">Email is required.</span> <span ng-show="myForm.email.$error.email">Invalid email address.</span> </span> </p> <p> <input type="submit" ng-click="Count()" ng-disabled="myForm.$invalid" title="Submit" value="Submit"> </p> </form>
编辑1:
我很奇怪,如果我将ng-model名称从电子邮件更改为email8,它将不再起作用.
<input type="email" name="emaill" ng-model="email8" required>
是否通过myForm html元素名称进行验证,该名称未使用ng属性定义.它是如何工作的?
ng-show="myForm.email.$dirty && myForm.email.$invalid"