【问题标题】:primeng : Dynamic load of p-tabPanelprimeng : p-tabPanel 的动态负载
【发布时间】: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

标签: angular primeng


【解决方案1】:

我用下面的ts代码解决了:

 for (let i=0;i<this.nofPages;i++)
{
  (async() => {
          while(this.pages[i]==undefined)
          await new Promise(resolve => setTimeout(resolve, 1));
          console.log (this.pages[i]);
        })();
}

不确定这是正确的解决方案。

谢谢你, 兹维卡

【讨论】:

  • 这不是要走的路。我评论了您的问题,询问了正确回答所需的详细信息
猜你喜欢
  • 1970-01-01
  • 2021-03-20
  • 2017-01-16
  • 2019-05-02
  • 2019-07-30
  • 2020-11-24
  • 1970-01-01
  • 2021-01-04
  • 2019-04-02
相关资源
最近更新 更多