How to synchronise Angular2 http get?

后端 未结 8 1367
無奈伤痛
無奈伤痛 2021-01-07 19:27

I understand using observable I can execute a method when the request is completed, but how can i wait till a http get is completed and return the response using in ng2 http

8条回答
  •  天命终不由人
    2021-01-07 19:50

    By looking at the angular source (https://github.com/angular/angular/blob/master/packages/http/src/backends/xhr_backend.ts#L46), it is apparent that the async attribute of the XMLHttpRequest is not getting used. The third parameter of XMLHttpRequest needs to be set to "false" for synchronous requests.

提交回复
热议问题