VK Chikkadamalla VK Chikkadamalla - 19 days ago 5
AngularJS Question

how to clear the fields when one page to another page come back in angular js

we have more than one page each page have forms. in Page 1 When i entered some data in one form and click on submit and navigate to another page 2, in that page2 i entered data to some fields and i navigating back to page 1 and i click on submit in page 1 and navigating to page 2 in that time the fields are not cleared. i need to clear the form fields using angularjs any one please help.

We are facing issue like below

enter image description here

We need like this below

enter image description here

Answer

The problem is with the cache-view, you can disable the cache with cache-view="false" or you can clean the fields manually using the enter event $ionicView.enter.
Is up to you where to disable the cache, eg.

Disable cache within state provider

$stateProvider.state('myState', {
   cache: false,
   url : '/myUrl',
   templateUrl : 'my-template.html'
})

Disable cache with an attribute

<ion-view cache-view="false" view-title="My Title!">
  ...
</ion-view>

If you want to clean the fields manually, you will have to do something like this in your controller:

$scope.$on('$ionicView.enter', function() {
    $scope.field1 = '';
    $scope.field2 = '';
    $scope.field3 = '';
});
Comments