【发布时间】:2020-06-06 11:12:28
【问题描述】:
以下 HTML+ts 代码的目标:
打开配置文件后,在 p-tabView 中显示 XXX p-tabPanel。
数字 XXX 取自文件。
有效。
但是在这些面板的循环中,对于每个面板,我想调用一个成员方法是这个 p-tabPanel 的类。
但是在这个阶段,面板的对象还没有定义。有一个竞争条件。
我怎样才能“延迟”这个直到对象被定义?
export class DirectFindComponent implements OnInit {
nofPages : number;
pageTitle : string;
items : number[];
pages : PageComponent[];
constructor(private waveform: WaveformService) {
this.nofPages = 0;
this.pageTitle = 'Page';
}
public Load
{
//Upon file load, this.nofPages gets a value
this.items = new Array (this.nofPages);
for (let i=0;i<this.nofPages;i++)
{
//This is not working. At this stage, Pages[i] is not defined yet. There is a race condition here
this.Pages[i].Load ();
}
}
ngOnInit() {
}
}
<div >
<p-tabView [styleClass]="'main'">
<p-tabPanel [header]='pageTitle+i' *ngFor="let item of items; let i = index" [selected]="i == 0">
<app-page [parent]="this" [id]="i" ></app-page>
</p-tabPanel>
</p-tabView>
</div>
【问题讨论】:
-
你在哪里设置过
Pages?