简体   繁体   English

使用ngFor实现引导表-Angular

[英]Implements bootstrap table with ngFor - Angular

I'm trying to add ngFor data in bootstrap table. 我正在尝试在引导表中添加ngFor数据。

Using 'table-striped table-dark' from https://getbootstrap.com/docs/4.1/content/tables/ https://getbootstrap.com/docs/4.1/content/tables/使用'table-striped table-dark'

But I doing it wrong in my html file, and can't fixed id. 但是我在html文件中做错了,并且无法固定ID。 I have all date in one column. 我把所有日期都放在一栏中。

This is my HTML: 这是我的HTML:

<div class="users-container">

  <div class="d-md-flex h-md-100 align-items-center">

    <div class="col-md-6 ">
      <div class="d-md-flex align-items-center text-center justify-content-center">
        <div class="logoarea pt-5 pb-5">
          <h2>All registered users</h2>
        </div>
      </div>
    </div>
  </div>
  <br>
  <br>

  <h3 *ngIf="!users.length">There are no users registered!</h3>

  <table class="table table-striped table-dark">
    <thead>
      <tr>
        <th scope="col">ID</th>
        <th scope="col">Name</th>
        <th scope="col">Email</th>
        <th scope="col">Create on</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <hr *ngIf="users.length">
        <div class="all-users" *ngFor="let users of users">
          <th scope="row">{{users.id}}</th>
          <td>{{users.name}}</td>
          <td>{{users.email}}</td>
          <td></td>
        </div>
      </tr>
    </tbody>
  </table>

  <!-- <hr *ngIf="users.length">
  <div class="all-users" *ngFor="let users of users">
    {{users.name}}
  </div> -->
</div>

This is the result: 结果如下:

在此处输入图片说明

Table bodies have a specific syntax, you can't just mess around with it and expect it to work. 表主体具有特定的语法,您不能仅仅弄乱它并期望它能工作。

<tr *ngFor="let users of users">
  <th scope="row">{{users.id}}</th>
  <td>{{users.name}}</td>
  <td>{{users.email}}</td>
  <td></td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM