【问题标题】:How to wait for for http response before loading child components?如何在加载子组件之前等待 http 响应?
【发布时间】:2016-03-24 03:13:21
【问题描述】:

我的 getSetup() 方法是从 ngOnInit 调用的,它将获取一些设置子组件(在模板中定义)所需的数据。 实际上,通过异步连接,我的子组件将在数据可访问之前创建。所以数据丢失了。

getSetup() {
    return this.http.get('http://localhost/apicommand/')
        .map((res) => { return res.json(); })
        .subscribe(data => { // SETUP CHILD COMPONENT })
        .catch((error) => console.log(error));
}

【问题讨论】:

    标签: angular angular2-services


    【解决方案1】:

    如果你不使用路由器,就没有办法 AFAIK。

    我只会用*ngIf="data" 包装模板以“禁用”组件,直到设置data

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 2019-10-28
      • 2019-03-07
      • 2018-11-16
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2020-08-21
      • 2011-08-17
      相关资源
      最近更新 更多