$ionicPlatform Current View/Controller Detection

Hi Everyone,

I need help!

I want the $ionicPlatform.on be activated on a certain view (HTML). In my case, when the user is filling up a form on my form view.

$ionicPlatform.on('pause', function() {
  $scope.InsertRecord(2); // call function to insert a record on the Database

The reason I’ve used this is, records must be saved when the user accidentally exits the app (temporarily). On it’s current state, it works fine (first load of the controller and view).

The problem is, it also run when the user exits the app even though he is not on the form view. So, the function is called every time the user exits the app (Home button for example).

Hope anyone has a solution for this.

Thank you.

Well all you’d have to do is check if the state is the current state.

So something like
if($state.current.name == ‘myFormState’) {

Thanks! I will give it a shot.

Hi @NorthMcCormick,

The function is called by how many times the app was closed. It increments when you try to do the same use-case.

What could be the cause of this? :frowning:

Solved it by using:

$scope.$on('$destroy', function(event) {
 // function

Referencing this thread for people who might encounter the same problem.


1 Like