简体   繁体   中英

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

i use $rootScope to send data to a controller from a nested state and view

It works between 'items' and rootSelector, It does not work between 'detail' and rootSelector

something blocks my rootScope events.

  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,
                   }
    }
        }
    };

I can send and receive events via $rootScope.broadcast and $scope.$on from PlaylistItemsController "items" to rootSelector

but i can't receive them if they come from the nested "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,                   
                }
            }
        }
    };

Ok, events didnt go through cause

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

was no code error in VS2015

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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