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)。