Javascript 在模板中显示整个对象

Javascript 在模板中显示整个对象,javascript,angular,Javascript,Angular,使用Angular 5,我试图显示对象的所有属性 使用对象集合,例如: testobjects = [ {"customer": "Me", "ID": "1"}, {"customer": "You", "ID": "2"}, {"customer": "Him", "ID": "3"}, {"customer": "Her", "ID": "4"} ]; <pre>{{testobject | json }}</pre> 使用HTM

使用Angular 5,我试图显示对象的所有属性

使用对象集合,例如:

testobjects = [
    {"customer": "Me", "ID": "1"},
    {"customer": "You", "ID": "2"},
    {"customer": "Him", "ID": "3"},
    {"customer": "Her", "ID": "4"}
];
<pre>{{testobject | json }}</pre>
使用HTML:

  <div *ngFor="let testobject of testobjects">
    <span>{{testobject}}</span>
    <span>{{testobject.customer}}</span>
  </div>

{{testobject}}
{{testobject.customer}}
我可以在模板中获取
testobject.customer
,但不能获取
testobject


如何显示整个对象?

您可以使用Angulars json管道


{{testobject | json}}

您可以使用Angulars json管道


{testobject | json}}
试试这个:
{{testobject | json}

试试这个:
{testobject | json}
使用


{{testobject | json}}
{{testobject.customer}}
使用


{{testobject | json}}
{{testobject.customer}}

您也可以使用pre标记对其进行格式化:

{{testobject|json}

您也可以使用pre标记对其进行格式化:

{{testobject|json}
JSON.stringify(你的对象)
JSON.stringify(你的对象)
<pre>{{testobject | json }}</pre>