Angular 11 HttpClient Generic Observable 映射服务值到 Class
Angular 11 HttpClient Generic Observable map service values into a Class
我在 .net 中使用 POST 服务,return 是下一个结构,服务 return 数据正确
enter image description here
public sendExcelInBase64ToBackEnd(data: any) {
this.customOptions = {
headers: this.customHttp.buildHeader(),
};
this.customHttp.Post<SerialResultDTO>('/serialsExcel', data, this.customOptions).subscribe(val => { // <- val data returns ok
this.serialResult = val;
let x = this.serialResult.Success;
console.log(x);
console.log(val.Success); // <- prints undefined
})
return null;
}
当我尝试在控制台 'val.Success' 中打印时,它打印出 undefined!!,为什么会这样??
我想在 angular 中将所有属性分配给自定义 class,但在 chrome 调试中它显示对象数据,但在分配给我的模型时 class 它变得不确定!!
有人可以帮助我!!我很感激!!
您的图像显示小写字母 success
,但您尝试记录标题字母 Success
。改为
public sendExcelInBase64ToBackEnd(data: any) {
this.customOptions = {
headers: this.customHttp.buildHeader(),
};
this.customHttp.Post<SerialResultDTO>('/serialsExcel', data, this.customOptions).subscribe(val => {
this.serialResult = val;
let x = this.serialResult.success;
console.log(x);
console.log(val.success);
})
return null;
}
我在 .net 中使用 POST 服务,return 是下一个结构,服务 return 数据正确
enter image description here
public sendExcelInBase64ToBackEnd(data: any) {
this.customOptions = {
headers: this.customHttp.buildHeader(),
};
this.customHttp.Post<SerialResultDTO>('/serialsExcel', data, this.customOptions).subscribe(val => { // <- val data returns ok
this.serialResult = val;
let x = this.serialResult.Success;
console.log(x);
console.log(val.Success); // <- prints undefined
})
return null;
}
当我尝试在控制台 'val.Success' 中打印时,它打印出 undefined!!,为什么会这样??
我想在 angular 中将所有属性分配给自定义 class,但在 chrome 调试中它显示对象数据,但在分配给我的模型时 class 它变得不确定!!
有人可以帮助我!!我很感激!!
您的图像显示小写字母 success
,但您尝试记录标题字母 Success
。改为
public sendExcelInBase64ToBackEnd(data: any) {
this.customOptions = {
headers: this.customHttp.buildHeader(),
};
this.customHttp.Post<SerialResultDTO>('/serialsExcel', data, this.customOptions).subscribe(val => {
this.serialResult = val;
let x = this.serialResult.success;
console.log(x);
console.log(val.success);
})
return null;
}