首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从服务获取数据时,Angular2+中的Tablesaw不起作用

从服务获取数据时,Angular2+中的Tablesaw不起作用
EN

Stack Overflow用户
提问于 2018-03-04 15:25:10
回答 2查看 181关注 0票数 0

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

代码语言:javascript
复制
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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-04 16:10:21

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

在组件选择器上添加一个*ngIf="results"。直到你从你的服务中得到数据,Angular才会运行这个组件。

票数 1
EN

Stack Overflow用户

发布于 2018-03-04 15:41:57

在组件选择器上添加一个*ngIf="results"。只有从服务中获得数据,Angular才会运行该组件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49093026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档