【问题标题】:Angular Material 6.4.7 Tree default opened by expand all [duplicate]Angular Material 6.4.7树默认打开全部展开[重复]
【发布时间】:2018-10-20 04:34:42
【问题描述】:

我在我的项目中使用了 Angular 材质树。是否可以默认打开树。

我通过 Tree 使用了最后一个示例,其中包含部分加载的数据: https://stackblitz.com/angular/pyyaxgjpqnn?file=app%2Ftree-loadmore-example.ts

感谢您的帮助。

我尝试了这个解决方案,但我遇到了这个错误: ERROR 错误:“ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。以前的值:'aria-expanded: false'。当前值:'aria-expanded: true'。”

ngAfterViewInit() { this.treeControl.expandAll(); }

【问题讨论】:

  • expandAll 工作正常吗?
  • 没有不工作

标签: angular angular-material


【解决方案1】:

无论出于何种原因,nestedTreeControl.dataNodes 都没有正确更新。使用您用于 nestedDataSource 的相同数据更新它,它应该可以工作。

 this.store.select(r => entity).subscribe(r => {
        this.nestedDataSource.data = [new Entity(JSON.parse(JSON.stringify(r)))];
        this.nestedTreeControl.dataNodes = this.nestedDataSource.data;
        this.nestedTreeControl.expandAll();
      })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-09
    • 2021-06-22
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多