简体   繁体   English

Angular JS:将范围数据传递给JSON

[英]Angular JS: pass scope data to JSON

Hello how can I pass $scope data to JSON when I initialise it? 您好,我初始化时如何将$scope数据传递给JSON?

eg I have scope users : 例如,我有范围users

$scope.users = [
  { name: "Camila Gilson" },
  { name: "Chloe Creighton" },
  { name: "Zoey White" }
];

I want to store users's info in json, is it possible? 我想在json中存储用户的信息,这可能吗?

Thanks? 谢谢?

Yes, this is what toJson and fromJson are for 是的,这就是toJsonfromJson的用途

angular.toJson($scope.users);

Will result in a string with JSON format and 将导致具有JSON格式的字符串和

angular.fromJson(yourJsonString);

Will convert it back. 将它转换回来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM