form. $setPristine() does not work + Angularjs

Asked

Viewed 675 times

0

I am trying to do a cleaning in a form, used $setPristine() from the Angularjs...

When trying to clean up a fluffy with:

$scope.reset = function(){
   $scope.form.$setPristine();
      $scope.perfilDeAcesso = '';
};

works normally but I’m trying to create a directive, and for it to still work I need a code similar to this:

$scope.limpar = function(modelForm,modelObjeto){
    console.log(modelForm);
    console.log(modelObjeto);
    modelObjeto = {};
    modelForm.$setPristine();
};

my exit in the console by double clicking on the button that calls Function

c {$error: Object, $name: "formPerfilDeAcesso", $dirty: true, $pristine: false, $valid:    true…}
perfilDeAcessoCtrl.js:73
Object {itensPerfilDeAcesso: Array[3], nome: "ssssssssssssss"}
perfilDeAcessoCtrl.js:74
c {$error: Object, $name: "formPerfilDeAcesso", $dirty: false, $pristine: true, $valid:  true…}
perfilDeAcessoCtrl.js:73
Object {itensPerfilDeAcesso: Array[3], nome: "ssssssssssssss"}

in this code section you can notice that the $setPristine() methdo worked because the $pristine attribute was changed, but the object was not set to vázio....

Can anyone tell me why?

  • I found out what it was... when I pass an object that is in my scope as parameter to another Cope or the same Cope has no way to modify the object, in case I decided implying a directive.

1 answer

1

I found out what it was... when I pass an object that is in my scope as parameter to another Cope or the same Cope has no way to modify the object, in case I decided implying a directive.

.directive('feResetform', function($compile, $http) {
   return {
   restrict: 'E',
   scope: {
     reOrigem: '=',
     reReset:  '=',
     reForm:    '='
   },
  template: 
    '<button ng-click="resetForm()" class="btn btn-warning" ng-if="!visualizar">'+
    ' Limpar  '+ 
    '</button>',
  replace: true,
  controller: ['$scope', function($scope){
    $scope.resetForm = function(){       
      $scope.reReset = angular.copy($scope.reOrigem);
      $scope.reForm.$setPristine();  
   }
  }]
}      

My tag passing the parameters..

 <fe-resetform re-origem="objetoOrigem" re-reset="perfilDeAcesso" re-  form="formPerfilDeAcesso"></fe-resetform>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.