这让我发疯了,我知道这一定是非常简单的我想念的东西!
我有一个返回JSON对象的服务:
[{"accountId":"0000004000006195","title":null,"firstName":"JOE","middleName":"BLOG","lastName":"BLOGGS","suffix":null,"primaryAddress":{"addressLine1":"TEST ADDRESS CLOSE","addressLine2":null,"addressLine3":"MY TOWN","town":"Washington","county":null,"country":"US","postcode":"PO9868"},"customerTelephones":[{"phoneNumber":"09876543455","type":"Alternate 1"},{"phoneNumber":"98654345676","type":"Alternate 2"}],"birthDate":108628400000}]
我正在尝试显示JSON的属性,例如:firstname using:
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.testJson = [{"accountId":"0000004000006195","title":null,"firstName":"JOE","middleName":"BLOG","lastName":"BLOGGS","suffix":null,"primaryAddress":{"addressLine1":"TEST ADDRESS CLOSE","addressLine2":null,"addressLine3":"MY TOWN","town":"Washington","county":null,"country":"US","postcode":"PO9868"},"customerTelephones":[{"phoneNumber":"09876543455","type":"Alternate 1"},{"phoneNumber":"98654345676","type":"Alternate 2"}],"birthDate":108628400000}]
});
HTML:
<p>{{testJson}}</p>
<p>{{testJson.firstName}}</p>
但由于某种原因,{{testJson.firstName}}显示为空白!
这是一个掠夺者:http://plnkr.co/edit/VWJfcXTPaDut2jqB4W3o?p=preview
有什么想法吗?
答案 0 :(得分:2)
答案 1 :(得分:2)
你的testJson似乎是一个数组。所以{{testJson[0].firstName}}
应该做到这一点!