-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
93 lines (89 loc) · 1.7 KB
/
app.js
File metadata and controls
93 lines (89 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var myApp=angular.module("myApp",[]);
myApp.service("ContactService",function(){
var uid=1;
var contacts=[{
'id':0,
'lname':'MohdAman',
'uname':'aman_7',
'dob':'1998-08-04',
'country':'India'}];
this.save=function(contact)
{
if(contact.id==null)
{
contact.id=uid++;
contacts.push(contact);
}
else
{
for(var i in contacts)
{
if(contacts[i].id==contact.id)
{
contacts[i]=contact;
}
}
}
};
this.get=function(id)
{
for(var i in contacts)
{
if(contacts[i].id==id)
{
return contacts[i];
}
}
};
this.delete=function(id)
{
for(var i in contacts)
{
if(contacts[i].id==id)
{
contacts.splice(i,1);
}
}
};
this.list=function()
{
return contacts;
} ;
});
myApp.controller("ContactController",function($scope,ContactService){
console.clear();
$scope.ifSearchUser=false;
$scope.title="List of Users";
$scope.contacts=ContactService.list();
$scope.saveContact=function()
{
console.log($scope.newcontact);
if($scope.newcontact==null || $scope.newcontact==angular.undefined)
return;
ContactService.save($scope.newcontact);
$scope.newcontact={};
};
$scope.delete=function(id)
{
ContactService.delete(id);
if($scope.newcontact!=angular.undefined && $scope.newcontact.id==id)
{
$scope.newcontact={};
}
};
$scope.edit=function(id)
{
$scope.newcontact=angular.copy(ContactService.get(id));
};
$scope.searchUser=function(){
if($scope.title=="List of Users"){
$scope.ifSearchUser=true;
$scope.title="Back";
}
else
{
$scope.ifSearchUser=false;
$scope.title="List of Users";
}
};
});