Wednesday, June 22, 2016

Quick AngularJS $location Tip

Usually we use the following line of code to navigate around within an AngularJS single page application:

$location.path(path);

This works fine most of the time, but depending on context, it might appear to do nothing. This is because the code only works within a digest loop. To ensure your navigation actually happens, wrap the call to path within a $timeout:

$timeout(function () {
    $location.path(path);
});

No comments:

Post a Comment

 
© I caught you a delicious bass.
Back to top