form $ setPristine () does not work + AngularJs

0

I'm trying to do a cleanup on a form, used $ setPristine () from angularJs ...

When attempting to clean a form with:

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

It works normally but I'm trying to create a policy, and for the same function I need a code similar to this:

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

My output on the console by double clicking on the button that calls the 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"}

Can anyone tell me why?

    
asked by anonymous 31.07.2014 / 06:06

1 answer

1

I discovered what it was ... when I pass an object that is in my scope as a parameter to another scope or to the same scope it has no way to modify the object, in the case I decided to implement 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>
    
01.08.2014 / 03:37