1

When transitioning from state parents.view to parents.view.childs - I do not see the controller associated with parents.view.childs being called/loaded. But prints within getChilds() is seen for which I see server responding with childs data.

But I cannot understand why childs controllers is not getting called. There are no errors on console.

Is there something wrong with using controllerAs : 'vm' in both states or something else ? Also please point how to debug state transitions ?

angular route file

.state('parents.view', {
  url: '/:parentId',
  templateUrl: 'modules/parents/client/views/view-parent.client.view.html',
  controller: 'parentsController',
  controllerAs: 'vm',
  resolve: {
    parentResolve: getparent
  },
  data: {
    pageTitle: 'parent {{ parentResolve.name }}'
  }
})
.state('parents.view.childs', {
  url: '/childs',
  templateUrl: 'modules/childs/client/views/list-childs.client.view.html',
  controller: 'childsListController',
  controllerAs: 'vm',
  resolve: {
    parentResolve: getchilds
  },
  data: {
    pageTitle: 'childs List'
  }
})

getchilds.$inject = ['$stateParams', '_childsService'];

function getchilds($stateParams, _childsService) {
  console.log('getting childs');
  return _childsService.query().$promise;
}

controller

(function () {
  'use strict';

  angular
    .module('childs')
    .controller('childsListController', childsListController);

  childsListController.$inject = ['$stateParams','$state', 'childResolve'];

  function childsListController($stateParams,$state,childResolve) {
    console.log('say hello',childResolve);
    vm.childs = childResolve;
  }
}());

edit made : get_childs() to getchilds()

5
  • 1
    Does the parent template contain ui-view? Commented Oct 31, 2016 at 11:15
  • I think you should add abstract your parent view Commented Oct 31, 2016 at 11:30
  • both questions are valid - yes there us ui-view and there is abstract parent view. Sorry, I havent posted as there are many routes in parents.* state Commented Oct 31, 2016 at 11:45
  • I had ui-view commented in parent view which led to this issue. @RadimKöhler had rightly pointed yseterday and I missed out double-checking it. thank you. Commented Nov 1, 2016 at 9:57
  • 1
    That is great to see, I added the answer and a link to a bit complex solution with more of the power hidden in UI-Router - multi and named views . Good luck sir ;) Commented Nov 1, 2016 at 10:01

2 Answers 2

1

To have an answer:

When a child is not loaded - always check that parent has a place(holder) for it

ui-view=""

Even better, if there are named views, we need for each of them a target

ui-view="name1"
ui-view="name2"

and use proper absolute naming in child views :{} definition. Check here for more details

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

Comments

1

You need to inject each resolve object as a dependency in the corresponding controller.

In your childsListController you are only injecting childResolve, while the only resolve object you have declared is

parentResolve: getchilds

I'm not very familiar with this syntax, but maybe the problem was simply forgetting to change 'parentResolve' to 'childResolve' in the parent.view.childs state?

1 Comment

That was a good catch - but unfortunately it still doesn't invoke childListController. I tried to simply introduce a bug by adding a typo error in injection of this controller - but there are no errors in console. I think it is not aware of the controller. I will change vm part to see if it helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.