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
|
#angular常用函数
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js"></script>
</head>
<body>
<div ng-app="app" ng-controller="ctrl">
</div>
<script type="text/javascript">
var m=angular.module('app',[]);
m.controller('ctrl',['$scope',function($scope){
var obj1={'name':'cxiong'};
//浅复制,对象赋值,复制内存地址
var obj2=obj1;
obj2.name='xmzhang';
console.log(obj1.name)
var obj1={'name':'cxiong'};
var obj3={};
//angular.copy 深复制,复制内存的值
angular.copy(obj1,obj3)
console.log(obj1.name)
//angular.uppercase 大写
console.log(angular.uppercase('asdf'))
//angular.lowercase 小写
console.log(angular.lowercase('ASDF'))
//angular.extend 扩充对象
angular.extend(obj1,{'age':29,'addr':'beijing'}),
console.log(obj1)
//angular.forEach 遍历数组
var adata=[
{'name':'cxiong','age':29},
{'name':'xmzhang','age':28}
]
angular.forEach(adata,function(v,k){
console.log(v.name+':'+k)
})
//angular.forEach 遍历对象
var odata={'name':'cxiong','age':29}
angular.forEach(odata,function(v,k){
console.log(v+':'+k)
})
//angular.toJson 对象转换为字符串
var od={'name':'cxiong','age':29}
var sd=angular.toJson(od)
console.log(sd)
//angular.fromJson 字符串转换为对象
od=angular.fromJson(sd)
console.log(od.name+':'+od.age)
}]);
</script>
</body>
</html>
|
转载于:https://blog.51cto.com/golechina/1956210