toJson:将对象或者数组 序列化 为json格式的字符串
fromJson:相反的过程
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta charset="UTF-8"> <title></title> <script src="js/angular.js"></script></head><body><p ng-controller="myCtrl"></p><script> var app = angular.module('myApp', ['ng']); app.controller('myCtrl', function ($scope) { //反序列化 var jsonStr = '{"name":"zhangsan","age":20}'; var result = angular.fromJson(jsonStr); console.log(result); console.log(resultStr); //Object age: 20name: "zhangsan"__proto__: Object //序列化:将对象或者数组 序列化 为json格式的字符串 方便和服务器端的交互 var resultStr = angular.toJson(result); // {"name":"zhangsan","age":20}// angular.lowercase/uppercase()// 遍历 var list = [100,200,300]; angular.forEach(list, function (value,key) { console.log(key,value); }) });</script></body></html>
以上是有什么angularjs内置的方法的详细内容。更多信息请关注PHP中文网其他相关文章!