控制台日志行为 - 无法读取对象属性

问题描述 投票:1回答:1

我正在建立一个有角度的网络应用程序

在组件的InInit中:

 public ngOnInit() {
    this.log.debug("INSTANCE", this.Instance);
    this.log.debug("ACTIVITY",this.Instance.entity);
    this.log.debug("CREATED AT", this.Instance.created_at);
        // Other staff...
 }

我得到以下结果:enter image description here

怎么可能呢?我无法读取应该在第一个日志显示时填充的对象的属性。

如果我按照建议打印键

Object.keys(this.Instance).forEach(data => {this.log.debug(data)});

我没有所谓的关键。

enter image description here

angular object properties undefined undefined-behavior
1个回答
1
投票

控制台日志是异步的。您可以同步获取对象的引用,但不能获取其属性。如果在展开对象之前修改了对象,则会看到更新的值。

© www.soinside.com 2019 - 2024. All rights reserved.