AngularJS 감청 경로 변화 방법
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AngularJS </title>
</head>
<body ng-app="ngRouteExample">
<div id="navigation">
<a href="#/home" rel="external nofollow" >Home</a>
<a href="#/about" rel="external nofollow" >About</a>
</div>
<div ng-view></div>
<script type="text/ng-template" id="home.html">
<h1> Home </h1>
<table>
<tbody>
<tr ng-repeat="x in records" style="background:#abcdef;">
<td>{{x.Name}}</td>
<td>{{x.Country}}</td>
</tr>
</tbody>
</table>
</script>
<script type="text/ng-template" id="about.html">
<h1> About </h1>
<p> :</p>
<p> :<input type="text" ng-model="name"></p>
<p> : {{name}}</p>
</script>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script>
<script type="text/javascript">
angular.module('ngRouteExample', ['ngRoute'])
.config(function ($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'home.html',
controller: 'HomeController'
}).
when('/about', {
templateUrl: 'about.html',
controller: 'AboutController'
}).
otherwise({
redirectTo: '/home'
});
})
.run(['$rootScope', '$location', function($rootScope, $location) {
/* */
$rootScope.$on('$routeChangeStart', function(evt, next, current){
console.log('route begin change');
});
$rootScope.$on('$routeChangeSuccess', function(evt, current, previous) {
console.log('route have already changed :'+$location.path());
});
}])
.controller('HomeController', function ($scope) {
$scope.records = [{
"Name" : "Alfreds Futterkiste",
"Country" : "Germany"
},{
"Name" : "Berglunds snabbköp",
"Country" : "Sweden"
},{
"Name" : "Centro comercial Moctezuma",
"Country" : "Mexico"
},{
"Name" : "Ernst Handel",
"Country" : "Austria"
}]
})
.controller('AboutController', function ($scope) {
$scope.name = ' ';
});
</script>
</body>
</html>
위의 예 는 AngularJS 1 입 니 다.Angular 2 도 사용 할 수 있 는 지,아직 시도 해 보지 않 았 습 니 다.검증 하고 기록 할 기회 가 있 습 니 다~이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
SpringMvc+Angularjs 멀티 파일 대량 업로드SpringMvc 코드 jar 가방 commons-fileupload commons-io spring-mvc.xml 구성 Controller 로컬 저장 AngularJs 코드 Form 양식 커밋 위에서 말한 것은 여...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.