Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch events of ion-view?

Tags:

ionic

According to the official doc, ion-view will emit its life-cycle events to help us control its logic.

But how can I catch these events?

like image 832
Yao Zhao Avatar asked Apr 16 '15 04:04

Yao Zhao


1 Answers

You can attach the events with the $scope in the relevant controller.

angular.module('ionicApp', ['ionic'])
.controller('HomeTabCtrl', function($scope) {
    $scope.$on('$ionicView.loaded', function (viewInfo, state) {
        console.log('CTRL - $ionicView.loaded', viewInfo, state);
    });
    $scope.$on('$ionicView.unloaded', function (viewInfo, state) {
        console.log('CTRL - $ionicView.unloaded', viewInfo, state);
    });
});
like image 98
shakib Avatar answered Nov 27 '22 22:11

shakib