angular - 表没有获得价值,因为价值未定义
问题描述
我正在尝试使用 Angular 中返回的数据在我的表格中进行投标。但是道具值是未定义的。
我的组件:
export class EquipmentsComponent implements OnInit {
form: any;
titleForm!: string;
equipments!: Equipments[];
constructor(private EquipmentService: EquipmentsService) { }
ngOnInit(): void {
this.EquipmentService.Getall().subscribe(result => {
this.equipments = result;
});
}
我的服务:
const httpOptions = {
headers: new HttpHeaders({
'Content-Type' : 'application/json'
})
};
@Injectable({
providedIn: 'root'
})
export class EquipmentsService {
url = "https://localhost:5001/api/Equipment";
constructor(private http: HttpClient) { }
Getall(): Observable<Equipments[]>{
return this.http.get<Equipments[]>(this.url);
}
GetWithId(EquipmentsID: number): Observable<Equipments>
{
const Url = `${this.url}/${EquipmentsID}`;
return this.http.get<Equipments>(Url);
}
PostEquipment(equipment: Equipments ): Observable<any>{
return this.http.post<Equipments>(this.url, equipment, httpOptions);
}
PutEquipment(equipment: Equipments): Observable<any>{
return this.http.put<Equipments>(this.url, equipment,httpOptions);
}
DeleteEquipment(equipmentId: number): Observable<any>
{
const Url = `${this.url}/${equipmentId}`;
return this.http.delete<Number>(Url, httpOptions);
}
}
我的界面:
export interface Equipments{
EquipmentsID: number;
Name: string;
SerialNumber: string;
Voltage: string;
ElectricCurrent: string;
Oil: string;
Date: Date;
}
我的 HTML:
<mat-card >
<div>
<button type="button" mat-raised-button color="primary">New Equipment</button>
</div>
<hr/>
<table class="w-100" *ngIf="equipments">
<h2>Gerenciar</h2>
<tr>
<th>Name</th>
<th>Serial Number</th>
<th>Voltage</th>
<th>Eletric Current</th>
<th>Oil</th>
<th>Date Register</th>
<th>Actions</th>
</tr>
<tr *ngFor="let equip of equipments">
<td>{{equip.Name}}</td>
<td>{{equip.SerialNumber}}</td>
<td>{{equip.Voltage}}</td>
<td>{{equip.ElectricCurrent}}</td>
<td>{{equip.Oil}}</td>
<td>{{equip.Date}}</td>
<td>
<button mat-raised-button (click)="Click(equip)" color="accent" >Update</button>
<button mat-raised-button color="warn" (click)="Clickstring(this.equip.Name)" >Delete</button>
</td>
</tr>
</table>
</mat-card>
我的调试:
我收到带有 DB 数据的设备对象,但值为equipments.Name
等Equipments.SerialNumber
。返回未定义。
我的页面:
我的页面没有显示数据,而是显示按钮,我使用它们进行调试,如果我单击更新返回一个包含所有道具的对象,并且单击删除时显示道具中的值,如图像调试所示。
解决方案
<td>{{equip.name}}</td>
您所有的属性名称都是帕斯卡,但它应该是骆驼案例
只需以小写字母开头的属性名称。
推荐阅读
- ios - React Native 安装 Cocoapods 依赖项错误
- postgresql - PostgreSQL 版本兼容 Windows 7 32 位
- c - 在setjmp之前用局部变量的地址调用空函数,有什么用?
- c# - 如何验证/清理一个 int 以便 Checkmarx 注意到我验证/清理了它
- javascript - Javascript验证字符串正则表达式
- sql - API 仅从数据库调用返回一个结果
- r - 如何在数据框中的每一行中提取唯一值?
- video - 无法使用 FFmpeg 将 MP4 重新混合到 MP4 中(在流 #1 中找不到编解码器的标签)
- javascript - 我如何在不取消所有内容的情况下更新我的嵌套对象?
- matlab - 分段线性逼近