在这个元素上匹配的元素不止一个 - Angular 4

时间:2018-05-18 09:27:41

标签: angular

您好我试图递归显示列表,我得到的错误是:

Uncaught Error: Template parse errors:
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
Conflicting components: TreeNodeComponent,TreeNode ("
    [ERROR ->]<tree-node [node]="categories"></tree-node>
  "): ng:///AppModule/TreeView.html@1:4

这就是这些组件的样子:

@Component({
  selector: 'tree-node',
  template: `
  <div>{{node.name}}</div>
  <ul>
    <li *ngFor="let node of node.children">
      <tree-node [node]="node"></tree-node>
    </li>
  </ul>
`
})
export class TreeNode {
  @Input() node: AdminCategory[];
}


@Component({
  selector: 'categories',
  template: `
    <tree-node [node]="categories"></tree-node>
  `,
})
export class TreeView {
  categories: AdminCategory[];

  constructor(private store: Store<AppState>, private dialog: MatDialog) {
    store.select('categoryState').subscribe(s => this.categories = s);
  }

  addCategory(category: AdminCategory) {
    this.store.dispatch(new AddCategory(new AdminCategory((category.id + 1), 'qwe', category.id)));
  }
....

我还在app.module.ts的声明中添加了它们。这有什么不对?我没有收到此错误消息,因为我没有声明两个相同的组件,第一个是tree-node,第二个是categories

0 个答案:

没有答案