ข้อความด่วนทันใจพยายามที่จะใช้จากเว็บเบราว์เซอร์ภายนอกรูปแบบ api ใน nestjs กับ axios.
@Injectable()
export class PIntegration {
constructor(private httpService: HttpService) { }
API = process.env.API || 'http://localhost:3000';
header = { headers: { 'Content-Type': 'application/json' } };
async getPrestacionById(id: string): Promise<Observable<IPrestacion>>{
return this.httpService.get(`${this.API}/prestacion/${id}`, this.header).pipe(map((res) => res.data));
}
}
และของบริการเรียนดูเหมือนนี้:
@Injectable()
export class ProductService{
constructor(private pIntegration: PIntegration){}
async producto(id: string) {
const infoPrestacion = await this.pIntegration.getPrestacionById(id);
console.log({ infoPrestacion })
if (infoPrestacion)
{
if (infoPrestacion.detalles) {
console.log(infoPrestacion.detalles)
console.log("tiene detalles")
}
}
return infoPrestacion;
}
}
แต่ถ้าฉันคอนโซล.ปูมบันทึกค่า"infoPrestacion"นี่คือผลลัพธ์ที่ได้:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
และมัน doesnt องไปสองตั้งแต่มันไม่ได้แก้ไขเลยนะ มันเป็นไปได้ที่จะรอสำหรับผลจนกระทั่งมันกแก้ไขเรียบร้อยแล้(ฉันไม่มี config สำหรับ HttpModule)? การกลับมาจริงๆจะได้รับวัตถุงตัวเอง"infoPrestacion"แต่ฉันต้องการที่จะทำงานกับค่าและไม่กลับมาที่วัตถุ.