How to synchronise Angular2 http get?

后端 未结 8 1356
無奈伤痛
無奈伤痛 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:44

    as you see, first callback waiting for a data from request and there you can go on with your logic (or use the third one)

    example:

    .. subscribe( data => { 
                  this.value = data; 
                  doSomeOperation;
                  }, 
                  error => console.log(error), 
                  () => {console.log("Completed");
                          or do operations here..;
                        }
    });
    

提交回复
热议问题