导入树组件以及芯片自动完成组件时出错

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

我正在尝试导入树组件以及芯片自动完成组件,我得到了这个

ERROR Error: Could not find a tree control for the tree.这里我搞乱使用2组件的构造函数,意味着我当时只能使用一个构造函数。

这是stackblitz链接

angular angular-material
1个回答
1
投票

错误错误错误:无法找到树的树控件显示,因为您定义的树控件为空。

正如您正确指出的那样,每个组件只能有一个构造函数实现。你可以做的是将两个构造函数的内容从材质示例组件合并为一个,如下所示:

constructor(private database: LoadmoreDatabase) {
    this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
      this.isExpandable, this.getChildren);

    this.treeControl = new FlatTreeControl<LoadmoreFlatNode>(this.getLevel, this.isExpandable);

    this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);

    database.dataChange.subscribe(data => {
      this.dataSource.data = data;
    });

    database.initialize();

    this.filteredFruits = this.fruitCtrl.valueChanges.pipe(
      startWith(null),
      map((fruit: string | null) => fruit ? this._filter(fruit) : this.allFruits.slice()));
  }

现在,树控件和角度材质树工作所需的其他所有内容都可以正确设置。

这是修改后的Stackblitz与一棵工作树。

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