angularjs - How to clear form after post? -


i'm creating app using ionic. after send values of form want clear form can't this.

how ?

form

<form name="empresa">     <div class="list">                                 <label class="item item-input"                                         ng-class="{'has-errors':empresa.nomeemp.$invalid, 'no-errors':empresa.nomeemp.$valid}">                                     <input type="text"                                             placeholder="nome"                                             name="nomeemp"                                             ng-model="empresa.nome"                                             ng-required="true">                                 </label>                                 <div class="error-container"                                      ng-show="(empresa.nomeemp.$dirty || !empresa.nomeemp.$pristine)"                                      ng-messages="empresa.nomeemp.$error">                                     <div ng-messages-include="templates/form-errors.html"></div>                                 </div>                                 </div>  <button type="button" class="button button-block button-energized"                       ng-disabled="empresa.$invalid" ng-click="addempresa(empresa);">cadastrar</button>  </form> 

controller

$scope.addempresa = function(empresa){             var _pathfile = document.getelementbyid("smallimage").src;       var _filename = _pathfile.substr(_pathfile.lastindexof('/') + 1);       if(_filename === 'no-image.png'){         $ionicloading.show({ template: app_messages.escolhaimagem, nobackdrop: true, duration: 2000 });       }else{           $ionicloading.show();           empresaapiservice.addempresa(empresa).then(function (data) {             $ionicloading.hide();             var retorno = json.parse(data.response);             if(retorno.status === 0){               $ionicloading.show({ template: retorno.msg, nobackdrop: true, duration: 2000 });             }             if(retorno.status === 1){                //clear form               delete empresa;                          empresa.$setpristine();               empresa.$setuntouched();                 $ionicloading.show({ template: retorno.msg, nobackdrop: true, duration: 2000 });              }            }, function (err) {                      $ionicloading.hide();                      }, function (progress) {              // progress handling goes here           });        }     } 

in controller after submission logic, set $scope.empresa.noma = ''; that's being bound form in application.

edit: setpristine() should work.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -