2016-09-21 2 views
1
Object {0: Object, 1: Object, 2: Object, 3: Object, 4: Object, httpStatus: 200, httpStatusText: null, httpBodyText: "[object Object],[object Object],[object Object],[object Object],[object Object]"} 

0:Object (example of object i opened to show content) 
CountryInitials : "US" 
Id: "101" 
CountryName: "United States" 
Population: 318.9 
__proto__: 
Object 
1:Object 
2:Object 
3:Object 
4:Object 

をオブジェクトリストを印刷カントが、これはオブジェクトが含まれ、そのオブジェクトので、イムは、データを受信する方法を示しています私のブラウザからの一例であり、私はその配列のようなHTMLでそれを扱いたいHTMLで

<div *ngFor="#obj of myList> 
     <div><b>Country ID:</b> {{obj.Id}} <b>Country Name:</b> {{obj. CountryName}}}</div> 
     </div> 

とそのが動作していない...私は私だけのリストを提示したい理由を、知らない:これはhtmlです

....私はそれがあると思ったが、そのは動作していません国IDと国名のオブジェクト。

例外:

EXCEPTION: Error trying to diff '[object Object]' in [myList in [email protected]:31] 

誰かが私にこれを理解してもらえますか?

ありがとうございました!

答えて

0

あなたは、テンプレート内のオブジェクトを印刷するには、パイプjsonを使用することができます:https://angular.io/docs/ts/latest/api/common/index/JsonPipe-pipe.html

@Component({ 
    selector: 'json-pipe', 
    template: `<div> 
    <p>Without JSON pipe:</p> 
    <pre>{{object}}</pre> 
    <p>With JSON pipe:</p> 
    <pre>{{object | json}}</pre> 
    </div>` 
}) 
export class JsonPipeComponent { 
    object: Object = {foo: 'bar', baz: 'qux', nested: {xyz: 3, numbers: [1, 2, 3, 4, 5]}}; 
} 
0

例外は、myList内の項目が一意ではないことを示します。おそらくあなたはいくつかの繰り返し要素を持っています。

アングルでは、列挙するアイテムを追跡する必要があります。

使用trackByオプション、

<li *ngFor="let item of items; let i = index; trackBy: trackByFn">...</li> 

下の構文を見つけるには、ディレクティブの完全な使用のためのhttps://angular.io/docs/ts/latest/api/common/index/NgFor-directive.htmlを参照してください。

0

あなたはkeyvaluekeyは0、1、などである いる... JSON形式を印刷するのに使用することができます(あなたの場合のように)valueはオブジェクトです(あなたの場合のように)...

関連する問題

 関連する問題