Hello I'm trying to recursive display an list, the error I get is:
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
This is how these components looks like:
@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)));
}
....
I also added them in declarations in app.module.ts. What is wrong here? I don't get this error message because I didn't declare two same components, the first one is tree-node
and the 2nd is categories
.