【问题标题】:Table didn't show row result even though API is working即使 API 正在工作,表格也没有显示行结果
【发布时间】:2021-03-05 05:40:06
【问题描述】:

我正在使用 Angular 11.0.2 显示来自 Sql-server 的表。
Sql server 工作正常,API 显示结果。
但是当我尝试在 Angular 中显示表格时,表格行没有显示。

在name.component.html中

<table class="table table-striped">
    <thead>
        <tr>
            <th>DepartmentId</th>
            <th>Department Name</th>
            <th>Options</th>
        </tr>
    </thead>

    <tbody>
        <tr *ngFor="let dataItem of DepartmentList">
            <td>{{dataItem.DepartmentId}}</td>
            <td>{{dataItem.DepartmentName}}</td>
            <td>
                <button type="button" class="btn btn-light mr-1">
                    Edit
                </button>
                <button type="button" class="btn btn-light mr-1">
                    Delete
                </button>
            </td>
        </tr>
    </tbody>
</table>

我认为是因为ngFor
所以我在网上尝试了多个建议,但仍然没有奏效。

import { Component, OnInit } from '@angular/core';
import {SharedService} from 'src/app/shared.service';

@Component({
  selector: 'app-show-dep',
  templateUrl: './show-dep.component.html',
  styleUrls: ['./show-dep.component.css']
})
export class ShowDepComponent implements OnInit {

  constructor(private service:SharedService) { }

  DepartmentList:any=[];


  ngOnInit(): void {
    this.refreshDepList();
  }

  refreshDepList(){
    this.service.getDepList().subscribe(data=>{
      this.DepartmentList=data;
    });
  }

}


【问题讨论】:

标签: sql-server angular


【解决方案1】:

尝试将异步管道添加到 ngFor 指令

【讨论】:

    【解决方案2】:

    你必须使用,

    this.DepartmentList=data.Data
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-04
      • 2014-07-26
      • 2023-03-21
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      相关资源
      最近更新 更多