在我的 AngularJS 应用程序中,每次请求更改我运行的页面:
$rootScope.$on('$locationChangeStart', function (event, next, current) {
var user;
$http.get('/api/Authentication/UserAuthenticated').then(function (data) {
console.log("call");
user = data.data;
});
console.log("end of call");
});
当我运行应用程序并测试正在发生的事情时,我在控制台中看到“通话结束”之前返回,console.log("call");
这意味着未设置用户。这意味着如果我想检查用户是否在更改路由时登录,用户将是未定义的。
我如何让 Angular 运行-> http 请求,然后才能继续?