如何在AngularJS中觀察路線變化?如何觀察/觸發(fā)路線上的事件變化?
如何在AngularJS中觀察路線變化?
www說
2019-08-12 11:07:34
TA貢獻1860條經(jīng)驗 獲得超8個贊
注意:這是AngularJS的舊版本的正確答案。有關更新版本
$scope.$on('$routeChangeStart', function($event, next, current) { // ... you could trigger something here ... });
以下事件也可用(它們的回調函數(shù)采用不同的參數(shù)):
$ routeChangeSuccess
$ routeChangeError
$ routeUpdate - 如果reloadOnSearch屬性已設置為false
請參閱$ route docs。
還有另外兩個未記錄的事件:
$ locationChangeStart
$ locationChangeSuccess
TA貢獻1862條經(jīng)驗 獲得超6個贊
$rootScope.$on( "$routeChangeStart", function(event, next, current) { //..do something //event.stopPropagation(); //if you don't want event to bubble up });
舉報