当我从服务中获取数据时,Angular2 +中的Tablesaw无法正常工作

时间:2018-03-04 07:25:10

标签: angular tablesaw

我在Angular 5项目中使用Tablesaw,但是当我从服务获取表数据但是它使用静态数据时,它不起作用。

export class MmrParticipationListComponent implements OnInit {
pid; mid; participationList; approversList = [];

constructor(private activatedRoute: ActivatedRoute, private programService: 
ProgramService) { }

ngOnInit() {
this.activatedRoute.queryParams.subscribe(params => {
  this.pid = +params['pid'];
  this.mid = +params['mid'];

  this.programService.getParticipationList(this.pid, this.mid, 0).subscribe(a => {
    this.participationList = a;

    this.programService
      .getParticipationListPerEachGroup(this.pid, this.mid, this.participationList.FillRepeater[0].MMRPTID)
      .subscribe(b => {     this.approversList = b;}
      );
    });
   });
  }
}

<table *ngIf="approversList" class="tablesaw tablesaw-stack table table-
hover table-custom" data-tablesaw-mode="stack">
<thead>
<tr>      <th>Role</th>   <th>Name</th>    </tr>
</thead>
<tbody>
<tr *ngFor="let item of approversList">    
<td>{{item.Role}}</td>  <td>{{item.Name}}</td>  
</tr>
 </tbody>
</table>

2 个答案:

答案 0 :(得分:1)

最有可能的是,在您从服务接收数据之前,Tablesaw正在初始化。

在组件选择器上添加*ngIf="results"。 Angular不会运行该组件,直到您获得服务中的数据为止。

答案 1 :(得分:0)

在组件选择器上添加*ngIf="results"。在获得服务数据之前,Angular不会运行组件。