-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrouterApp.js
39 lines (33 loc) · 1.14 KB
/
routerApp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
angular.module('routerApp', ['ngRoute'])
.config(function ($routeProvider) {
$routeProvider
.when('/home', {templateUrl: 'views/home.html'})
.when('/userList', {templateUrl: 'views/userList.html', controller: 'userListCtrl'})
.when('/user/:userId', {templateUrl: 'views/userDetail.html', controller: 'userDetailCtrl'})
.otherwise({redirectTo: '/home'});
}).
controller('userListCtrl',function($scope, $http, $location) {
var reqPromise = $http.get('sample.json');
reqPromise.success(function(data) {
$scope.userList = data;
});
reqPromise.error(function(data) {
console.error("Ajax 에러 발생");
});
$scope.goDetail = function(userId) {
$location.url('/user/'+userId);
};
}).
controller('userDetailCtrl',function($scope, $http, $routeParams, $location) {
var id = $routeParams.userId;
var reqPromise = $http.get('sample-'+id+'.json');
reqPromise.success(function(data) {
$scope.user = data;
});
reqPromise.error(function(data) {
console.error("Ajax 에러 발생");
});
$scope.back = function() {
$location.url('/userList')
};
});