Angular JS,无法处理rootScope

时间:2017-04-28 09:33:35

标签: angularjs

我使用的是角1.5.x

下面是我的路由逻辑,但我无法获得rootScope的句柄。 请问你能告诉我什么不对吗?

更新:我已根据下面的答案文章更新了路由逻辑。 我仍然无法击中控制器。

(function() {
'use strict';

angular
    .module('icebergApp')
    .config(setupRouting);

setupRouting.$inject = ['$stateProvider', '$urlRouterProvider', '$rootScope'];

function setupRouting($stateProvider, $urlRouterProvider, $rootScope) {
    $urlRouterProvider.otherwise("/iceberg-ui");
    $stateProvider
        .state('iceberg.reconlist', {
            url: "/iceberg-ui",
            templateUrl: "app/iceberg/reconlist/reconlist.view.html",
            controller: 'ReconListController as vm'
        })

    $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
        console.log('$stateChangeStart to '+toState.name+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
    });
    $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams, error){
        console.log('$stateChangeError - fired when an error occurs during transition.');
        console.log(arguments);
    });
    $rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){
        console.log('$stateChangeSuccess to '+toState.name+'- fired once the state transition is complete.');
    });
    $rootScope.$on('$viewContentLoading',function(event, viewConfig){
        console.log('$viewContentLoading - view begins loading - dom not rendered',viewConfig);
    });

    $rootScope.$on('$stateNotFound',function(event, unfoundState, fromState, fromParams){
        console.log('$stateNotFound '+unfoundState.to+'  - fired when a state cannot be found by its name.');
        console.log(unfoundState, fromState, fromParams);
    });
}
}());

CONTROLLER

(function() {
'use strict';

var myApp = angular.module('iceberg.reconlist', ['ui.router']);
myApp.controller('ReconListController', ReconListController);

ReconListController.$inject = ['ReconListService'];

function ReconListController(ReconListService) {
    var vm = this;
}
}());

MODULE

(function() {
'use strict';

angular.module('icebergApp', [
      'ui.router',
    'iceberg.reconlist'
]);

angular.module('iceberg.reconlist', [     
]);

}());    

1 个答案:

答案 0 :(得分:0)

<{1}}中未提供

$rootScope。那里只有提供商。您必须做的就是拆分代码,将.config()部分放入$rootScope方法。

.run