Angular 7 Sweet Alert显示动态表

时间:2019-03-13 10:29:26

标签: javascript angular sweetalert

我在Angular 7中使用了Sweet Alert 2,并且我试图显示动态表。

Json:

[
  {
    "name": "Steve",
    "age": 23
  },
  {
    "name": "John",
    "age": 30
  },
  {
    "name": "Daniel",
    "age": 18
  }
]

我尝试使用* ngFor,但不幸的是,它无法正常工作。

Swal({
  position: 'center',
  type: 'info',
  title: `Class Information`,
  html: `<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr *ngFor="let person of persons">
    <td>{{person.name}}</td>
    <td>{{person.age}}</td>
  </tr>
</table>`,
});

或者,我正尝试显示自己的组件。

  Swal({
      position: 'center',
      type: 'info',
      title: `Class Information`,
      html: `<class-component [inputClassInformation]="classInformationJson"></class-component>`
    });

这不能正常工作。

我的目标是显示以下弹出窗口: enter image description here

1 个答案:

答案 0 :(得分:2)

您需要在Angular 7中使用ngx-sweetalert2来显示动态表

ngx-sweetalert2

<swal title="Fill the form, rapidly">
  <table>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
    <tr *ngFor="let person of persons">
      <td>{{person.name}}</td>
      <td>{{person.age}}</td>
    </tr>
  </table>
</swal>