How to re-trigger the $scope.$on( "$ionicView.enter", function()...) from a callback within itself?


#1

I have a view that does a bit of network accessing when it is entered (inside the $scope.$on( “$ionicView.enter” …) function.

If there is a network failure the user gets an alert with the choice to try the operation again.

At this point I would like the “on view entered” function to be run again, but I can’t figure how to retrigger it.
(I have tried $state.go to myself, but nothing happends…)


#2

It is possible to inject $rootScope into your controller and use $rootScope.broadcast() method in your callback function to implements this?

It may just like $rootScope.$broadcast("$ionicView.enter"), and don’t forget setting a variable to log down what times you want to re-trigger event and abort the callback function.


#3

Sounds like a workable solution. But I don’t know how to build the arguments to target only one specific view scope…
$rootScope.$broadcast("$ionicView.enter") will target all child views with listeners on this event, and I have several of those that should not be run.

Can’t seem to find any docs on this…?


#4

So… So far I have found that doing

$timeout( function() {
   $scope.$parent.$broadcast( "$ionicView.enter" );
});

works pretty well.