【发布时间】:2017-07-28 12:12:59
【问题描述】:
我的主要组件中有以下 html:
<app-loc-list-item *ngFor="let loc of locs; let i = index" [loc]="loc" [i]="i"></app-loc-list-item>
LocListItemComponent 看起来像这样:
import { Component, OnInit, Input } from '@angular/core';
....
export class LocListItemComponent implements OnInit {
@Input() loc: Location;
@Input('i') index: number;
selected: boolean = false;
onLocationSelect() {
this.selected = !this.selected;
}
}
现在,这些小组件可以有任意数量,0 和 n 之间的值可以是 selected = true。我现在想接收具有selected = true 的每个组件的index 值。
如何访问这些索引值?
【问题讨论】:
-
您是否正在更改从 LocListItemComponent 中选择的内容?
-
好点,我确实这样做了,在函数中编辑了这样做。这是一个简单的点击监听器。