반응형
AngularJS에서 경로 변경을 감시하는 방법?
경로 변경시 이벤트를 어떻게보고 트리거합니까?
참고 : 이것은 기존 버전의 AngularJS에 대한 정답입니다. 업데이트 된 버전에 대해서는 이 질문 을 참조하십시오 .
$scope.$on('$routeChangeStart', function($event, next, current) {
// ... you could trigger something here ...
});
다음과 같은 이벤트도 사용할 수 있습니다 (콜백 함수에는 다른 인수가 사용됨).
- $ routeChangeSuccess
- $ routeChangeError
- $ routeUpdate- reloadOnSearch 특성이 false로 설정된 경우
$ route 문서를 참조하십시오 .
문서화되지 않은 다른 두 가지 이벤트가 있습니다.
- $ locationChangeStart
- $ locationChangeSuccess
$ locationChangeSuccess와 $ locationChangeStart의 차이점 은 무엇입니까?를 참조하십시오 .
시계를 특정 컨트롤러에 배치하지 않으려는 경우 Angular 앱에서 전체 응용 프로그램에 대한 시계를 추가 할 수 있습니다 run()
var myApp = angular.module('myApp', []);
myApp.run(function($rootScope) {
$rootScope.$on("$locationChangeStart", function(event, next, current) {
// handle route changes
});
});
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
//..do something
//event.stopPropagation(); //if you don't want event to bubble up
});
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
//if you want to interrupt going to another location.
event.preventDefault(); });
참고 URL : https://stackoverflow.com/questions/14765719/how-to-watch-for-a-route-change-in-angularjs
반응형
'Programming' 카테고리의 다른 글
설치된 판다 버전을 찾는 방법 (0) | 2020.05.05 |
---|---|
리소스를로드하지 못했습니다 : net :: ERR_INSECURE_RESPONSE (0) | 2020.05.05 |
스프링 애플리케이션 컨텍스트 얻기 (0) | 2020.05.05 |
로컬 저장소를 추가하고 원격 저장소로 취급하는 방법 (0) | 2020.05.05 |
C ++ 11 자동 키워드가 너무 많습니까? (0) | 2020.05.05 |