我有两个组成部分:列表和详细信息
In 列表组件我想渲染多个细节组件.
列表组件.ts
@Component({
selector: 'detail',
templateUrl: './detail.component.html'
})
export class DetailComponent {
@ViewChild('details') details;
public items = {
// ...
}
}
列表.组件.html
<detail *ngFor="let item of items" #details></detail>
注意#details模板引用变量。我想访问所有详细组件。可以使#details变量数组?
@ViewChildren('details') details:QueryList<DetailComponent>;
ngAfterViewInit() {
console.log(this.details.toArray());
this.details.changes.subscribe(changes => {
console.log(this.details.toArray());
});
}
也可以看看angular 2 / typescript :获取模板中的元素 https://stackoverflow.com/questions/32693061/angular-2-typescript-get-hold-of-an-element-in-the-template/35209681#35209681
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)