Skip to content

Instantly share code, notes, and snippets.

@samny
Last active August 29, 2015 14:25
Show Gist options
  • Save samny/227a7a2e59a2e20b4259 to your computer and use it in GitHub Desktop.
Save samny/227a7a2e59a2e20b4259 to your computer and use it in GitHub Desktop.
Wait for promise resolve before triggering route
angular
.module('app', ['ui.router'])
.config(function ($urlRouterProvider) {
$urlRouterProvider.deferIntercept();
});
.run(function ($rootScope, $urlRouter, WaitForThis) {
var deRegister = $rootScope.$on('$locationChangeSuccess', function (e) {
e.preventDefault();
WaitForThis.init().then(function () {
deRegister(); // if this only needs to be checked once, de-register the listener.
$urlRouter.sync();
});
});
$urlRouter.listen();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment