JavaScript 对象数组显示为空,但它在扩展时有值,无法访问值

JavaScript array of objects showing up as empty yet it has values on extending, not able to access values

我正在尝试将对象数组分配给 angular 自定义指令,如下所示

<div custom-directive [customDirective]="arrayOfObjects"> </div>

但是在指令的 class 中获得了一个空数组,但它包含一个在控制台上展开它的对象列表。

@Directive({
  selector: '[custom-directive]'
})
export class CustomDirective implements OnInit {

  @Input() customDirective;

  constructor(private elmentRef: ElementRef) { }

  ngOnInit(): void {
  console.log(this.customDirective);
  .......
  }
}

无法访问值,看起来有点像这样

这可能是由于异步行为 注意:我相信您正在从异步任务中获取这些对象数组

查看此以获取更多信息 - https://angular.io/guide/observables-in-angular