标签:angularjs
#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>
标签:angularjs
原文地址:http://f1yinsky.blog.51cto.com/12568071/1955921