【发布时间】: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;
});
}
}
【问题讨论】:
-
@AmirNorouzpour 不。加了之后连路由都不行了。
-
@silver_river 使用chrome.google.com/webstore/detail/allow-cors-access-control/…进行测试
-
@AmirNorouzpour Ralpharoo 感谢您的帮助。我重做evertyhing,然后一切都好。 Mybe我错过了一些步骤。不过,我还学到了其他东西。
标签: sql-server angular