星期三, 9月 11, 2013

[AngularJS] 如何重設表單

最近透過Angular在送出表單時,想要清除表單資料,於是將綁定欄位的model重設時,
會造成表單欄位有設require屬性,會丟出相對應的錯誤訊息。
因為在1.0.x版本時,這樣並沒有將整個表單的狀態重設

可以參考這篇
http://stackoverflow.com/questions/12603914/reset-form-to-pristine-state-angularjs-1-0-x

不過在1.1.x版提供一行簡單的指令可以解決重設表單的問題

 $scope.你的表單id.$setPristine();

範例
                             
 $scope.signup_form.$setPristine();
                             

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails