0
My basic code:
ngOnInit() {
const today = Date.now()
this._schedulesService.getSchedules().subscribe(
(res: SchedulesModel[]) => {
this.schedulesToday = res
this.schedulesToday.filter((schedule: SchedulesModel) => schedule.dtPlanejada == today.toString())
this.schedulesToday.forEach((obj) => {
obj.dtPlanejada = formatDate(obj.dtPlanejada)
obj.containerdata = this._containersService.get__container__by_id(obj.idContainer)
})
}
)
}
Snippet of code connecting to my server.
get__container__by_id(id: string): Observable<ContainersModel> {
const token: any = JSON.parse(localStorage.getItem('user')).token
return this.http.get<ContainersModel>(`${API_URL}/containers/${id}`, setTokenHeader(token)).pipe(map(response => response))
}
My question is: How should I do for that function get__container_by_id(id)
return my direct object so that the return is stored directly in the variable obj.containerdata
?
I don’t quite understand your context, your problem is that the return of the request is not being assigned to ob.containerdata? Because it’s an http request, I think you should subscribe to get_container_by_id as well, and when you get the response from the server assign the containerdata, if you can explain the context a little better maybe I can help better
– veroneseComS
Exactly that’s the problem. I don’t know how to write the correct mapping of the server response. I have already subscribed to two methods and yet the answer remains a Subscriber object. How should I write to that method
get__container_by_id()
returns a mapped object in typeContainersModel
?– Paulo Moraes