操作 DOM 和 TS 数据

Manipulate DOM and TS data

我通过在我的数据库中搜索来显示 ID 列表。在我的 ngfor 循环中,我拖了一个子组件。我可以检索每个子组件中的每个 ID 吗?

我想获取players.ts中"GameToDisplay.key"的每个值,以便通过此键调用每个数据。 谢谢你

<div *ngFor="let GameToDisplay  of GamesToDisplay | async">
{{GameToDisplay.key}}
<app-players></app-players>
</div>

您需要传递数据并在 players.ts

上访问它
<div *ngFor="let GameToDisplay  of GamesToDisplay | async">
{{GameToDisplay.key}}
<app-players [data]="GameToDisplay.key"></app-players> //data is not the fixed name
</div>

在你的players.ts

@Input('data') key: any; // replace any by your key type;

 ngOnInit(){
 console.log(key);
}