2
라우팅과 나는 자바 스크립트에서 몇 가지 다른 URL에 대한 경로 아주 간단한 각도 프로젝트가 :사용자 정의 상태를 입력하고 국가 종료 코드
function RootController($scope) {};
function PageOneController($scope) {};
angular.module('mymodule', []).config(
['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl: "templates/root.html",
controller: RootController
}).when('/page1/', {
templateUrl: "templates/page1.html",
controller: PageOneController
}).otherwise({redirectTo: '/'});
}]
);
다 큰 지금까지 작동을하지만, 내가 필요합니까 길을 입력하고 나가면 일부 자바 스크립트 기능을 실행할 수 있습니다. 예 :
$routeProvider.when('/', {
templateUrl: "templates/root.html",
controller: RootController,
onenter: function() { console.log("Enter!"); },
onexit: function() { console.log("Exit!"); }
});
Angular? 상태/경로를 입력 할 때 이벤트 리스너를 바인딩해야하며 종료 할 때 해당 이벤트를 삭제하고 해체해야합니다.