ui.router嵌套状态,嵌套视图:$ rootScope。$ on $ rootScope。$ broadcast doesnt connect

时间:2018-04-11 15:39:27

标签: angularjs angular-ui-router angularjs-rootscope

我使用$ rootScope从嵌套状态向视图发送数据并查看

它适用于'项目'和rootSelector, 它在' detail'之间无效。和rootSelector

阻止我的rootScope事件。

  var listState = {
        name: 'playlist.list',
        parent: 'playlist',
        url: '/list?',
        resolve: {
             playlistsDb: resolvePlaylistsFromDb,
        },
        views: {

            // target the unnamed view in the playlist state
            '@playlist': {
                templateUrl: 'app/playlists/list/list.html',
                controller: 'PlaylistListController',
                controllerAs: 'list'
            },

            // target the content view in the playlist.list state
            'content@playlist.list': {
                templateUrl: 'app/playlists/list/items/items.html',
                controller: 'PlaylistItemsController',
                controllerAs: 'items'
            },


            // target the rootSelector view in the playlist state
            'rootSelector@playlist.list': {
                templateUrl: 'app/selector/rootSelector.html',
                controller: 'rootSelectorController',
                controllerAs: 'rootSelector',
                resolve: {
                    selectedPlaylistId: resolveSelectedPlaylistId,
                   }
    }
        }
    };

我可以通过$ rootScope.broadcast和$ scope。$ on发送和接收事件 来自PlaylistItemsController" items"到rootSelector

但是如果它们来自嵌套的" detailState"

,我就无法收到它们
 var detailState = {
        name: 'playlist.list.detail',
        parent: 'playlist.list',
        url: '/detail/:id',
        views: {
            'detail@playlist.list': {
                templateUrl: 'app/playlists/list/detail/detail.html',
                controller: 'PlaylistDetailController',
                controllerAs: 'detail',
                resolve: {
                    playlistDb: resolvePlaylistDb,                   
                }
            }
        }
    };

1 个答案:

答案 0 :(得分:0)

好的,事件没有经过原因

 $scope.$on('removeTrackFromPlaylist'), function (event, args) { }

在VS2015中没有代码错误