Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在运行中使用$state.current_Angularjs_Angular Ui Router_Angular Services - Fatal编程技术网

Angularjs 在运行中使用$state.current

Angularjs 在运行中使用$state.current,angularjs,angular-ui-router,angular-services,Angularjs,Angular Ui Router,Angular Services,我有一个角度服务的代码 $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) { if (storageService.getValue("login_credentials") && (storageService.getValue("auto_login"))) {

我有一个角度服务的代码

 $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) { 
            if (storageService.getValue("login_credentials") && (storageService.getValue("auto_login"))) {
                httpService.doLogin(function (){
                    if (!toState.data.require_authentication) {
                        return 0;
                    }
                    if (!checkStorageIntegrity(toState.data)) {
                        event.preventDefault();
                        $state.go("page.login");
                        return;
                    }
                    validate(function (data) {
                        if (!data.fn.result.done) {
                            $state.go("page.login");
                        }
                        storageService.setKey("auto_login", false);
                    });
                });
            }

但是我想将httpService.doLogin({….})移到.run中,而不必声明。如果我使用$state.current,请给我
{name:,url:“^”,视图:null,摘要:true}
。如何获取当前状态?

在我的例子中,$state.current在javascript代码中一直是空的,尽管我在view-s中使用过它。。。但也许您可以尝试$location.path()。。它将为您提供url,因为您只检查字符串值,您可以只检查url@MaanusIndov谢谢你的回复。但对我来说,这不是一个很好的解决方案。我尝试了这个方法,在运行时它有toState.name@MaanusIndov,我不需要使用$rootScope.$on($stateChangeStart'in.run。我只想知道当前状态(不需要toState)。