javascript - 如何使用 *ngFor 循环的 Angular 在表的 <td> 字段内使用 *ngIf 条件?

标签 javascript html angular angular6 ngfor

实际上,在我的 component.ts 文件中,我使用了 api 来调用该方法,并且它返回了对象数组。

enter image description here 我的问题开始于我尝试在标签中使用 ngIf 根据 client.auditorGroup 隐藏/显示列,因为它是 true 或 false(它是 bool 类型),但它没有给我访问权限:

enter image description here

enter image description here

第一个代码:

ngOnInit() {

   this.http.get('http://localhost:8080/api/selections')
      .subscribe((data: any[]) => {
        this.clients = data;
        console.log(this.clients);


        this.chRef.detectChanges();

        const table: any = $('table');
        this.dataTable = table.DataTable();
      });

  }

在我的 html 代码中我使用了这个编辑删除,它是 h

<table class="table table-bodered">

          <thead>
            <tr>
              <th>Mag No</th>
              <th>SelectionDate</th>
              <th> SelectedBy</th>
              <th>PanEximNumber</th>
              <th>Name</th>
              <th>Address</th>
              <th>PhoneNumber</th>
              <th>SelectionType</th>
              <th>Action</th>

            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let client of clients">
              <td>{{client.selectionId}}</td>
              <td>{{client.selectionDate}}</td>
              <td>{{client.selectedBy}}</td>
              <td>{{client.panEximNumber}}</td>
              <td>{{client.name}}</td>
              <td>{{client.address}}</td>
              <td>{{client.phoneNumber}}</td>
              <td>{{client.selectionType}}</td>
              <td *ngIf="{{client.auditorGroup}}==false">Edit Delete</td>

            </tr>


          </tbody>

        </table>

最佳答案

使用*ngIf时删除插值{{}}

 <td *ngIf="!client.auditorGroup">Edit Delete</td>

关于javascript - 如何使用 *ngFor 循环的 Angular 在表的 <td> 字段内使用 *ngIf 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53165733/

相关文章:

javascript - C3js 退出零值数据点上的曲线

javascript - 将对象内部的对象加载到 html 表中

javascript - 如何制作 2 列投资组合页面,左边是导航,右边是当图像悬停在左侧导航词上时显示的图像

javascript - 让事件监听器在插入的 HTML 按钮上工作

jquery - Javascript 从谷歌获取建筑物的图像

html - 使用 bootstrap 元素不会出现在新行上

Angular 4 路由

javascript - "greater than"文本输入值比较的意外结果

Angular |创建一个 Observable 不工作

Angular-4 d3 v4 问题 : Property 'x' does not exist on type 'HierarchyNode'