Reputation: 407
I'm running a AngularJS webapplication with ionic.
I got a headpage where I see a list of articles. When I click on this you'll get a seperate page with tabs. When i go from the headpage to a tab-page the controller loads for the first time.
$scope.selectArt = function(artikel) {
api.setCurrItem(artikel.artnr);
$state.go('tab.voorraad');
}
The controller is will be loaded.
app.controller('ArtikelsCtrl', function($scope, $state, $location, api, artikels) {
console.log("loaded");
};
I have a backbutton where I can go back to the headpage. When I click on a item the selectArt function will be loaded again but the 'ArtikelsCrtl' will not be loaded again.
App.js
$stateProvider
.state('artikels', {
url: '/artikels',
templateUrl: 'app/artikels/artikels.html',
controller: 'ArtikelsCtrl'
})
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'app/_shared/tabs.html'
})
.state('tab.voorraad', {
url: '/voorraad',
views: {
'tab-voorraad': {
templateUrl: 'app/voorraad/voorraad.html',
controller: 'VoorraadCtrl'
}
}
})
Anyone got an idea why the controller don't load on the 2nd time? It looks like the page just hide and show up again on $state.go.
Upvotes: 0
Views: 102
Reputation: 4302
Controllers are initialised once per view. When you pass the controller option you are specifying how it is constructed. Changing view leaves the controller in existence.
Upvotes: 1