Yao Zhao
Yao Zhao

Reputation: 4613

How to catch events of ion-view?

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?

Upvotes: 9

Views: 7429

Answers (1)

shakib
shakib

Reputation: 5469

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);
    });
});

Upvotes: 12

Related Questions