【发布时间】:2016-07-14 12:15:05
【问题描述】:
我有一个 json 文件,我想绑定一些变量以显示在 UI 上。
testjson= {"date":1468497879354,"faulty":"F-3","mileage":"150,900 mls","search":[]}
在html中
<div>
<span>{{ testjson }}</span><--- here i am getting above json object
Date:{{date}}
Faulty:{{faulty}}
Mileage: {{mileage}}
<div>
如何绑定才能获得特定的对象值??
【问题讨论】:
-
你将不得不解析 json
angular.fromJson -
我也做了解析,我无法获得特定对象的值 testjson = JSON.parse(testjson); this.assign =testjson .date
-
只需使用
testjson?.date -
我是这样做的,但它显示错误RIGINAL EXCEPTION: TypeError: Cannot read property 'mileage' of undefined
-
标签: json typescript angular