【问题集】Error Cannot read property 'globals' of null

来源:互联网 发布:ubuntu autotools 编辑:程序博客网 时间:2024/05/29 14:08
问题:
在路由跳转的onEnter事件中,用到了$state.go()方法,运行时报Error Cannot read property 'globals' of null错误。

解决办法:
为$state.go()方法增加一个延时,如下:
accountDevEdit: {    url: '/account/auth/edit',    template: accountDevEditTemplate,    controller: accountDevEditController,    sideMenu: "menuAccount",    resolve: {        isCreate: function(devService) {            return devService.getDevInfo(baseConfig.baseUrl + "/dev/auth/getInfo")        }    },    onEnter: function(isCreate, $state, $timeout) {        var timeoutId;        if (!isCreate.data) { //未进行认证            timeoutId = $timeout(function() {                $state.go('accountDevCreate');                $timeout.cancel(timeoutId);            }, 10);        } else {            if (isCreate.status != 3) { //认证但非失败状态                timeoutId = $timeout(function() {                    $state.go('accountDev');                    $timeout.cancel(timeoutId);                }, 10);            }        }    }}



解释说明:
Another solution for anyone facing this issue: as silly as it seems, try adding a $timeout around your transition from onEnter, if possible. The bug seems to occur due to processing a new transition during onEnter, so the $timeout will allow the original transition to complete before starting a new one, fixing the problem for me.

来源: https://github.com/angular-ui/ui-router/issues/326
原创粉丝点击