forked from spbooks/mean1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.js
47 lines (40 loc) · 1.07 KB
/
webapp.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
40
41
42
43
44
45
46
47
var app = angular.module('app', ['ngRoute', 'ngResource']);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/view', {
templateUrl: 'view.html',
controller: 'view'
})
.when('/edit/:employeeId', {
templateUrl: 'edit.html',
controller: 'edit'
})
.otherwise({
redirectTo: '/'
});
}]);
app.factory('EmployeeService', ['$resource', function ($resource) {
return $resource('/employees/:employeeId', {}, {
list: {
isArray: true
},
get: {
isArray: false
}
});
}]);
app.controller('view', ['$scope', 'EmployeeService', function ($scope, EmployeeService) {
$scope.employees = [];
$scope.firstName = $scope.lastName = '';
EmployeeService.list(function (data) {
$scope.employees = data;
});
}]);
app.controller('edit', ['$scope', 'EmployeeService','$routeParams', function ($scope, EmployeeService, $routeParams) {
$scope.employee = {};
EmployeeService.get({
employeeId: $routeParams.employeeId
}, function (data) {
$scope.employee = data;
});
}]);