從同伴開發者繼承項目後,它仍然是我使用AngularJS的第一天。我想知道,我的界面上有一個登錄/註冊表單,一旦提交了項目/表單,就會隱藏起來。現在,一旦用戶提交了有正確或正確的方式來清除它的條目的形式,並恢復項目上的.ng-pristine類。原因是用戶應該選擇註銷然後再次登錄(或另一個用戶希望註冊)表單已填充並且已經應用驗證css。我不想要這個,我希望一切都是空的,沒有應用CSS。清除所有輸入並恢復.ng-pristine點擊
我可以在JavaScript中做到這一點(顯然)然而,與AngularJS是一種不同的方法,我想知道如果我應該以另一種方式處理這個問題,而不是通過表單項循環,並附加一個類到每個項目,同時清除它的價值。
這是我的形式之一的例子
<form name="signupForm" novalidate ng-submit="register(user)">
<div><label for="email">email:</label><input type="email" id="email" name="email" required ng-model="user.email" ng-minlength=4></div>
<div><label for="userName">Username:</label><input type="text" name="userName" id="userName" ng-model="user.userName" required ng-pattern="/^[A-Za-z0-9 \-_.]*$/" ng-minlength=4></div>
<div><label for="firstName">Vorname:</label><input type="text" name="firstName" id="firstName" ng-model="user.firstName" required ng-pattern="/^[A-Za-z \-_.]*$/" ng-minlength=3></div>
<div><label for="lastName">Nachname:</label><input type="text" name="lastName" id="lastName" ng-model="user.lastName" required ng-pattern="/^[A-Za-z \-_.]*$/" ng-minlength=4></div>
<div><label for="password1">Passwort:</label><input type="password" name="password1" id="password1" ng-model="user.password1" required ng-minlength=4></div>
<div><label for="password2">Passwort wiederholen:</label><input type="password" name="password2" id="password2" ng-model="user.password2" valid-password2 ng-minlength=4 pw-check="password1"></div>
... and so on
非常感謝
使用$ setPristine()和清除模型 –