0

Using, Angular UI-Router, I have the following state:

$stateProvider
    .state('blog.article', {
      url: '/:slug',
      template: '<article></article>',
      views: {

      }
    });

I'm parsing the article slug in the url, which becomes available in $stateParams. However, I would like to target a parent state's named ui-view using this slug, is it possible to set the name of custom view to the slug in my case? So views object looks something like this:

views: {
   'stateParams.slug': {/* etc */}
}
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
styke
  • 2,116
  • 2
  • 23
  • 51
  • I'm really at a loss at what you're trying to do. The `views` object in a call to `$stateProvider.state` sets up nested views for that state. The `:slug` is available in `$stateParams` for every nested view in that state - *injected to view's controller*. The parent view of `blog` won't see any `$stateParams` because it's a fixed path e.g. `/`. – dewd May 19 '16 at 22:15

1 Answers1

0

...However, I would like to target a parent state's named ui-view using this slug, is it possible to set the name of custom view to the slug in my case?

No. The views : {} setting is static, not dynamic.

But there are still dynamic parts like controllerProviders, templateProviders, resolvers etc. And you should think about handling your logic there

views: {
   'viewName': {
       templateProvider: ...
       controllerProvider: ...
       resolver: ...
   }
}

see:

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335