我有一个名为$scope.informationData
的变量,其内容(作为console.log的输出)如下所示:
{"completed":100,"pending":50,"defects":20,"overdue":10}
如果我在我的HTML中使用这个:
<div class="huge">{{ informationData.overdue }}</div>
则为空。我不认为绑定有什么问题,因为如果我做{{ informationData }}
,那么它输出与上面相同的JSON。
我想我只是使用错误的语法来读取数据-我需要改变informationData.overdue
以看到数字10出现吗?
反序列化json
$scope.informationData = angular.fromJson($scope.informationData);
你应该把你的值放在引号里,而不是你的键。像这样修改json::
{"completed":"100","pending":"50","defects":"20","overdue":"10"}
或
{completed:"100",pending:"50",defects:"20",overdue:"10"}