AngularJs .$setPristine to reset form

后端 未结 6 646
耶瑟儿~
耶瑟儿~ 2020-12-05 09:15

I been struggling to reset form once form is submitted. Someone posted this Here which I want to make it work but no success. Here is my My Code Example.

$scop

6条回答
  •  既然无缘
    2020-12-05 10:03

    I solved the same problem of having to reset a form at its pristine state in Angular version 1.0.7 (no $setPristine method)

    In my use case, the form, after being filled and submitted must disappear until it is again necessary for filling another record. So I made the show/hide effect by using ng-switch instead of ng-show. As I suspected, with ng-switch, the form DOM sub-tree is completely removed and later recreated. So the pristine state is automatically restored.

    I like it because it is simple and clean but it may not be a fit for anybody's use case.

    it may also imply some performance issues for big forms (?) In my situation I did not face this problem yet.

提交回复
热议问题