繁体   English   中英

ui.router嵌套状态,嵌套视图:$ rootScope。$ on $ rootScope。$ broadcast不连接

[英]ui.router nested States, nested Views: $rootScope.$on $rootScope.$broadcast doesnt connect

我使用$ rootScope从嵌套状态和视图向控制器发送数据

它在'items'和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,                   
                }
            }
        }
    };

好的,事件没有通过原因

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

VS2015中没有代码错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM