Home > Web Front-end > JS Tutorial > body text

Are there any built-in methods in angularjs?

一个新手
Release: 2017-10-10 10:11:17
Original
1380 people have browsed it


Serialization, Deserialization

toJson: Serialize an object or array into a string in json format

fromJson: The reverse process

<!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(&#39;myApp&#39;, [&#39;ng&#39;]);

  app.controller(&#39;myCtrl&#39;, function ($scope) {

  //反序列化
    var jsonStr = &#39;{"name":"zhangsan","age":20}&#39;;    
    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>
Copy after login

The above is the detailed content of Are there any built-in methods in angularjs?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template