sql-server - 即使 API 正在工作,表格也没有显示行结果
问题描述
我正在使用 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;
});
}
}
解决方案
尝试将异步管道添加到 ngFor 指令
推荐阅读
- java - 以编程方式加载弹簧配置
- macos - 如何在 Mac 或裸机上的 x86-64 程序集中使用 monitor / mwait 指令
- node.js - Testcafe 脚本失败并出现此错误“调用导致重定向,因此不应导致其他操作。:\n 没有可用的堆栈跟踪”
- php - php邮件功能有效,但我没有收到任何邮件
- asp.net-web-api - 从根 url 重定向到 /swagger/ui/index 问题
- excel - VBA代码跳过整个部分,代码单独工作,但组合时不工作
- spring - spring boot 未从配置的外部 oracle 数据库中获取数据
- reactjs - 做出反应。访问根组件的 props
- amazon-web-services - 负载均衡器上的入口 ip 白名单 - aws k8s
- c# - 编写 T4 生成的代码以分隔输出文件