代码之家  ›  专栏  ›  技术社区  ›  Rama Krishna

动态调用子组件方法

  •  -1
  • Rama Krishna  · 技术社区  · 8 年前

    我有导出表格的要求,我使用ngFor提交了我的自定义表格。

    当我试图单独导出每个表时,我得到了错误的结果(每次只导出一个表),我使用了ViewChildren帮助。

    我的代码如下

    <div ngFor="let eachObj of objList:let i=index;">
        <button (click)="exportReport(i)">Export</button>
        <myTable [data]="eachObj"></myTable>
    </div>
    
        @ViewChildren(MyCustomTable) tables: QueryList<MyCustomTable>;
            exportReport(i:number){
            let mytables: MyCustomTable[] = this.tables.toArray();
            mytables[i].exportMyTable('pdf');
       }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Rama Krishna    8 年前

    我的方法是对的,我还坚持做别的事情

    推荐文章