Angular的初学者。最近首次使用$location.path时,出现了一个问题,就是改变路径后
$location.path('/result')
需要点击两次后才会跳转。
解决办法:
在后面加上$scope.$apply()
$location.path('/result');
$scope.$apply();
$apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries).
因为我写的那段代码是在一个第三方库(jQuery)的回调函数中执行的,所以会出现问题(具体是什么问题、是什么原因等有时间再研究~~,大家有研究过的发个链接,谢谢啦~)。