Answer the question
In order to leave comments, you need to log in
Angular Http how?
Hello!
Guys tell me this question!
I made a service
getWinTickets():Observable<Tickets[]>{
return this.http.get<Tickets[]>('http://localhost:3001/win');
}
getTickets():Observable<Tickets[]>{
return this.http.get<Tickets[]>('http://localhost:3000/tickets');
}
setTickets(ticket:Tickets):Observable<Tickets[]>{
return this.http.post<Tickets[]>('http://localhost:3000/tickets',ticket);
}
setWinTickets(ticket:Tickets[]):Observable<Tickets[]>{
return this.http.post<Tickets[]>('http://localhost:3001/win',ticket);
}
onWinNumber() {
this.winnumberService.getTickets().subscribe(ticket => {
this.ticket = ticket.filter(c => c.id % 3 == 0);
});
this.winnumberService.setWinTickets(this.ticket).subscribe();
console.log(this.ticket);
}
Answer the question
In order to leave comments, you need to log in
There may be a problem with synchronism
Try to do setWinTickets exactly when getTickets will work
onWinNumber() {
this.winnumberService.getTickets().subscribe(ticket => {
this.ticket = ticket.filter(c => c.id % 3 == 0);
this.winnumberService.setWinTickets(this.ticket).subscribe();
console.log(this.ticket);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question