首页 > 解决方案 > Angular 2+递归嵌套问题

问题描述

我遇到了递归嵌套组件的一个奇怪问题。嵌套基于一个数组,其中每个下一个项目将在嵌套中增加一层(块对象中的数组称为实体):

<app-chunk [chunk]="chunk" [increment]="(increment + 1)"></app-chunk>

-

@Input() chunk;

ngOnInit() {
    // Check if it's the final nesting
    if (!this.chunk.entities || this.chunk.entities.length <= this.increment) {
      this.isThrough = true;
    } else {
      this.isThrough = false;
    }
  }

到目前为止,嵌套工作正常,但是,当我更改数组时,更改不会反映在整个嵌套组件中。

例如,从数组中删除,应该会导致嵌套组件的一级消失,这不会发生。基本上,我需要完全重新渲染递归组件树,对吧?

但是,这无论如何都可以做到吗?(已经尝试过 NgZone.run, ApplicationRef.tick) => 还没有成功

标签: javascriptangulartypescriptnestedangular6

解决方案


推荐阅读