-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular_service,value.html
More file actions
63 lines (51 loc) · 1.36 KB
/
angular_service,value.html
File metadata and controls
63 lines (51 loc) · 1.36 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
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.2/angular.min.js"> </script>
<script>
// service object
var personman = function(info){
this.perinst = info;
}
// service object for first name
personman.prototype.getfirst = function(){
return this.perinst.first;
}
// service object for last name
personman.prototype.getlast = function(){
return this.perinst.last;
}
// service object for full name with seperator
personman.prototype.getfull = function(seperator){
return this.perinst.first + seperator + this.perinst.last;
}
// service object
angular.module('myApp', [])
// value
.value('info', {
first: '' ,
last : '',
})
// value
// service object instance
.service('ser', personman)
// storing into a service named 'ser'
// including dependencies 'info'-- value , 'ser' -- service
.controller('cont', function($scope, info, ser){
info.first= 'sai';
info.last = 'teja';
$scope.inst = ser;
})
// writing first and last properties to 'info' and storing 'ser' instance into inst
</script>
</head>
<body ng-app="myApp">
<div ng-controller="cont">
first name : {{inst.getfirst()}}
last name : {{inst.getlast()}} </br>
full name : {{inst.getfull('-')}}
<input type="text" ng-model="inst.perinst.first">
<input type="text" ng-model="inst.perinst.last">
</div>
</body>
</html>