Angular subscribe push object to array

后端 未结 3 1208
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 00:17

I am making angular application and where i am having an empty array like,

  users: any = [];

Then i am making a service call in ngOn

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 00:57

    Angular can use Promises and Observables to handle asynchronous operations such as this http get request. There's lots of information on this concept and here is a good starting point: Promise vs Observable

    To further elaborate, you could wrap the http get request in a method that returns an Observable, and then subscribe to that method and wait for it to return a result before executing the log statement.

提交回复
热议问题