0

I have the following state configuration. How can I get id parameters in index state @ view so that it could be accessible by both, left and detail views controllers? Now if I try to access it via $state.params.id it is undefined, but if I console.log($state) I can see the parameter in my console. I only need the parameter if available on first load of left view.

$stateProvider
    .state('index', {
        url: '/',
        views: {
           '@' : {
               template: '/**/'
               resolve: {
                   params: function ($state) {
                       return $state.params.id;
                   }
               }
           },
           'left@index' : {
               template: '/**/',
               controller: 'AppController',
               controllerAs: 'app'
           },
           'main@index' : { 
               template: '/**/'
           }
     })
     .state('index.detail', {
         url: '/:id',
         views: {
             'detail@index' : {
                 template: '/**/',
                 controller: 'DetailController',
                 controllerAs: 'detail',
              }
         }
});
5
  • 1
    It simply does not make sense. Parent params can be consumed in children, but not vice versa. Check e.g. stackoverflow.com/q/24301754/1679310 Commented Oct 6, 2015 at 19:08
  • I need that the left view also get the id parameter, without reinitializing its controller Commented Oct 6, 2015 at 19:16
  • But how would that view know about it WITHOUT re-init controller? Will you use watching? that is against the principle of the UI-Router. Rather create more named view and let them update when child param is changing. E.g. check here layout style stackoverflow.com/q/25667660/1679310 - which could be used here as well Commented Oct 6, 2015 at 19:18
  • Here is what you need stackoverflow.com/q/32448285/1679310 ... try to observe the tricke with parent view, and children updating that (having access to the params if provided) Commented Oct 6, 2015 at 19:22
  • My bad, I only need the parameter on first load of controller of left view Commented Oct 6, 2015 at 19:32

0

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.