Fel*_*ikZ 3 events promise angularjs angularjs-routing
我有一些像这样的代码:
$scope.$on("$locationChangeStart", function(event, newPath, oldPath) {
// Do some sync checks
if (!$scope.isPageAllowed($location.path()))
{
// Prevent default for some reason
event.preventDefault();
}
});
Run Code Online (Sandbox Code Playgroud)
当我试图promises像这样解决:
$scope.$on("$locationChangeStart", function(event, newPath, oldPath) {
// Do some async checks
$scope.fooPromises().then(function (data) {
// Prevent default for some reason when promises resolved (only if resolved)
event.preventDefault();
});
});
Run Code Online (Sandbox Code Playgroud)
我得到了全成event(因为异步执行的),并在一段时间后阻止event时promises得到解决.
有没有办法event与我联系promises,所以在承诺得到解决之后它会被完全阻止而且在功能结束后没有直接?
对不起,这不起作用:-).事件纯粹是同步的.
你正在寻找$ route.resolve.异步解析/拒绝路由,给出控制器数据或只是检查一些东西.
http://www.egghead.io/video/Kr1qZ8Ik9G8