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',
              }
         }
});
andrius.k
  • 799
  • 1
  • 10
  • 26
  • 1
    It simply does not make sense. Parent params can be consumed in children, but not vice versa. Check e.g. http://stackoverflow.com/q/24301754/1679310 – Radim Köhler Oct 06 '15 at 19:08
  • I need that the left view also get the id parameter, without reinitializing its controller – andrius.k Oct 06 '15 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 http://stackoverflow.com/q/25667660/1679310 - which could be used here as well – Radim Köhler Oct 06 '15 at 19:18
  • Here is what you need http://stackoverflow.com/q/32448285/1679310 ... try to observe the tricke with parent view, and children updating that (having access to the params if provided) – Radim Köhler Oct 06 '15 at 19:22
  • My bad, I only need the parameter on first load of controller of left view – andrius.k Oct 06 '15 at 19:32

0 Answers0