I'm trying to create a nested treeview.
@Component({
selector: "myItem",
template: `
<li *ngIf="!Array.isArray(data)"> {{data.text}} </li>
<ul *ngIf="Array.isArray(data)">
<myItem *ngFor="let x of data" [(data)] = "x.data"> </myItem>
</ul>
`
})
export class MyItemComponent {
static root = true;
data: any;
constructor() {
if (MyItemComponent.root) {
this.data = [
{ text: "foo" },
[{ text: "bar" }, { text: "foo" }]
];
MyItemComponent.root = false;
}
}
}
The error is
Can't bind to 'data' since it isn't a known native property ("ta.text}} ][data] = "x.data"> "): MyItemComponent
EDIT: how can I implement a delete button? The template should look like:
<li *ngIf="!Array.isArray(data)"> {{data.text}} <button (click)="clicked()"> delete me</button> </li>
<ul *ngIf="Array.isArray(data)"> <button (click)="clicked()"> delete me</button>
<myItem *ngFor="let x of data" [(data)] = "x.data"> </myItem>
</ul>
What would be the click
function?