首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用*ngFor作为子组件角中的表

如何使用*ngFor作为子组件角中的表
EN

Stack Overflow用户
提问于 2018-05-17 12:50:02
回答 1查看 455关注 0票数 0

我想显示用户的:我必须在循环(*ngFor)中放置<tr>标记

UserComponent.html

代码语言:javascript
复制
<div class="theme-2">
  <div class="example-container mat-elevation-z8">
    <app-user *ngFor="let user of users" [user]="user"></app-user>
  </div>
</div>

UserComponent.html

代码语言:javascript
复制
<table>
    <tr>
        <th>No.</th>
        <th>Name</th>
        <th>Email</th>
        <th>Created_at</th>
        <th>Updated_at</th>
    </tr>
    <tr>
        <td>{{ user.id }}</td>
        <td>{{ user.name }}</td>
        <td>{{ user.email }}</td>
        <td>{{ user.created_at }}</td>
        <td>{{ user.updated_at }}</td>
    </tr>
</table>

现在结果!

所有的表标记都进入了*ngFor,我如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-17 12:53:47

*ngFor放在表上,而不是组件本身上。现在,您正在创建大量app-user组件的副本,这不是您想要的。

代码语言:javascript
复制
<app-user [users]="users"></app-user>
代码语言:javascript
复制
<table>
    <tr>
        <th>No.</th>
        <th>Name</th>
        <th>Email</th>
        <th>Created_at</th>
        <th>Updated_at</th>
    </tr>
    <tr *ngFor="let user of users">
        <td>{{ user.id }}</td>
        <td>{{ user.name }}</td>
        <td>{{ user.email }}</td>
        <td>{{ user.created_at }}</td>
        <td>{{ user.updated_at }}</td>
    </tr>
</table>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50391912

复制
相关文章

相似问题

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