Angular 9 http call with nestjs backend

♀尐吖头ヾ 提交于 2020-04-18 04:00:30

问题


I have an Angular (9) frontend with nestjs backend rest api (in nodejs) The endpoint I call in the backend does some fairly complex operations and it takes about 2 min to respond. In the frontend I use subscribe to subscribe to the response like this:

this.metaService.subscribe(
  result => {
  //Handle result
  },
  error => {
    this.subscription.unsubscribe();
    console.error('Error: ' + error);
  },
  () => {
    this.subscription.unsubscribe();
    console.error('Completed');
  });

The problem is that in the backend it starts executing code over and over again. Note that it does not execute the http call again (I can see this from the network tab in Developer tools), it stays in Pending all the time) It seems this works if I do

.pipe(take(1)).subscribe(

then it does not do the looping in the backend but it immediately completes the subscription (and the http is in cancelled state in network tab) I am running this in my localhost on a windows machine (linux subsystem). Node version is 12.14.1

Does anyone what is causing this and how to fix it ?

-Jani


回答1:


This is not the answer: I think I was able to figure this out. I had several static async methods in a for loop which seemed to be causing this. I don't really now why but when I removed the methods and converted them to non-static async methods (still in for loop) I am not experiencing the issue anymore. I am not sure why they were static in the first place...



来源:https://stackoverflow.com/questions/60418011/angular-9-http-call-with-nestjs-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!