0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

ui.router.state.$state

$state.go(to, params, {reload : true})

I hope it can help you.

1 Comment

Changed to this but not working. $state.go('tab.voorraad', {}, {reload : true});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.