1

友人、私はangularjsが初めてなので、angularjsの検証にname属性が必要な理由を説明してください

<form  name="lform" novalidate>
<input type="text"  name="userName" ng-model="userName" required novalidate/>
<span style="color:red" ng-show="lform.userName.$dirty && lform.userName.$invalid">
<span ng-show="lform.userName.$error.required">Username is required.</span>
</span>
<br/>
</form>

name="userName"コードが機能しない場合は、これについて説明してください。

Update: If I remove "ng-model" it is not working, but I can change "ngmodel='newName'" is working, please explain this reason also.
4

2 に答える 2

1

答えはあなたのコードにあります。

<span ng-show="lform.userName.$error.required">Username is required.</span>

Angular は入力名を使用してエラー関連情報を保存しています。

lform – フォーム名
username – 入力した名前

于 2014-10-26T12:14:29.787 に答える