Angular Object.key-检索,仅从对象中获取一个属性 [英] Angular Object.key - Retrieve,get only one property from object

查看:441
本文介绍了Angular Object.key-检索,仅从对象中获取一个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么只能从对象中检索一个属性?

How can i retrieve only one property from object?

在此示例中,我的对象具有2个属性:name和id

in this example i have object with 2 properties: name and id

   <div *ngFor="let post of objectKeys(_postArrayMatch.team1)">
      Team1: {{ _postArrayMatch.team1[post]}}
    </div>

我要排除ID,如何只显示name属性?

I want to exclude the id, how can i show only the name property?

我试图做这样的事情,但是那样行不通

I tried to do something like this, but it doesn't work that way

   <div *ngFor="let post of objectKeys(_postArrayMatch.team1)">
    Team1: {{ _postArrayMatch.team1[post].name}} 
 </div>

作为回应,我只是空了

团队1:

团队1:

推荐答案

如果只想显示一个元素,请不要使用*ngFor. ngFor用于在一个可迭代对象中循环多个元素.

If you want to show only one element, don't use *ngFor. ngFor is for looping over multiple elements in an iterable.

<div>
  Team1: {{ _postArrayMatch.team1.name}}
</div>

这篇关于Angular Object.key-检索,仅从对象中获取一个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆