-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.js
executable file
·44 lines (37 loc) · 1 KB
/
controller.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
var App = angular.module('myApp', ['angularUtils.directives.dirPagination']);
App.controller('EmpCtrl', function ($scope, $http){
$http.get('emp.json').success(function(data) {
$scope.emp = data;
});
$scope.removeRow = function(name){
var index = -1;
var comArr = eval( $scope.emp );
for( var i = 0; i < comArr.length; i++ ) {
if( comArr[i].name === name ) {
index = i;
break;
}
}
if( index === -1 ) {
alert( "Something gone wrong" );
}
$scope.emp.splice( index, 1);
};
$scope.addRow = function(){
$scope.emp.push({'name':$scope.name,'job': $scope.job, 'sal':$scope.sal});
$scope.name='';
$scope.job='';
$scope.sal='';
};
$scope.removeItem = function(index){
$scope.emp.splice(index,1);
}
$scope.editItem = function(index){
$scope.editing = $scope.emp.indexOf(index);
}
$scope.saveField = function(index) {
if ($scope.editing !== false) {
$scope.editing = false;
}
};
});