Call controller method on state change

I am creating an ionic app based on the tabs template. I am using the Cordova-SQLitePlugin and I managed to write, read and delete data in a database, tested on device. It all works OK if I put everything in the same tab. I like to separate the data entry, table data display and chart of the data in 3 separate tabs. The problem I am having is I need a way to call my $scope.loaddata method in my controller, when there’s a transition to the second or the third tab. How can I achieve this? I’ve done some reading around $stateProvider but not getting very far.

Thank you.

Sounds like the ion-tab on-select="" is what you are looking for.

See this Pen

I am listening for tabSelection events and taking specific action when it happens

Look at the MainCtrl and then look how I set the controller on the whole tab group

1 Like