Im की कोशिश कर रहा से उपयोग करने के लिए एक बाहरी एपीआई में 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;
}
}
लेकिन अगर मैं console.लॉग मूल्य "infoPrestacion" इस परिणाम है:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
और एक दूसरे को पाने के बाद से यह हल नहीं अभी तक. यह संभव है करने के लिए परिणाम के लिए प्रतीक्षा करें जब तक यह हल (मैं नहीं है किसी भी विन्यास के लिए HttpModule) ? वापसी वास्तव में हो जाता है, वस्तु ही "infoPrestacion" लेकिन मैं काम करने की जरूरत के साथ मूल्यों और वापस नहीं है कि वस्तु.