Angular中的UI路由器子状态不加载控制器

时间:2015-10-06 00:00:36

标签: angularjs angular-ui-router

我在为每个子状态加载控制器/模板时遇到问题。我在每个州控制器中都有一个console.log,但它们并没有触发。任何想法将不胜感激!

意图是始终为后面的每个子状态加载艺术家。

var stateConfig = ['$stateProvider', function($stateProvider) {
// State Configurations
$stateProvider
.state('artist', {
  abstract: true,
  url: '/' + artistSlug,
  controller: "artistCtrl",
  resolve: {
    artist: function(artist){
      return artist.getArtist();
    }
  }
})
.state('events', {
  parent: 'artist',
  url: '',
  controller: 'eventsCtrl',
  templateUrl: "/templates/artist/events.html"
})

1 个答案:

答案 0 :(得分:1)

我认为你需要修改你的州/参数

它应该是艺术家 - > artists.artist - > artists.artist.events。然后,如果你去//site.com/artists/justintimberlake/events,它将解决艺术家和事件

  var stateConfig = ['$stateProvider', function($stateProvider) {
  // State Configurations
  $stateProvider
    .state('artists', {
      abstract: true,
      url: '/artists'
    })
    .state('artists.artist', {
      url: '/:artistId',
      controller: 'artistCtrl',
      template: '<div ui-view>Artist Template Wrapper for Artist and Events</div>',
      resolve: {
        artist: function (artist, $stateParams) {
          return artist.getArtist($stateParams.artistId);
        }
      }
    })
    .state('artists.artist.events', {
      url: '/events',
      controller: 'eventsCtrl',
      templateUrl: '/templates/artist/events.html',
      resolve: {
        events: function (artist, $stateParams) {
          return artist.getArtistEvents($stateParams.artistId);
        }
      }
    })
}];