I should make a Primeng tree. This is my model.
export interface Profiles {
active?: true,
description?: string,
function?: [
string
],
id?: number,
macroFunction?: string,
name?: string,
nodeTree?: [
{
children?: [
string
],
data?: {
description?: string,
flag?: true,
functionFK?: string,
id?: number,
order?: number,
parent?: number
}
}
]
}
I don't know how to do the http call and the rest.
I thought about something like that: service:
postProfiles(): Promise<Profiles > {
const url = 'profiles/create';
return this.http.post<Profiles >(url, {})
.toPromise()
}
ts --> http
node: Profile[];
selectedNode: Profile;
ngOnInit() {
this.nodeService.postProfiles().then(node=> this.selectedNode= node);
}
HTML
<p-tree [value]="node" selectionMode="single" [(selection)]="selectedNode"></p-tree>
Can someone help me? What's wrong? Thanks in advance!
Done! I hope it'll be useful
node:any;
this.ricercaService.getTree().subscribe( (res) => {
this.node = res.nodeTree;
},
(error) => { c
onsole.log(error);
});
HTML –
<p-tree *ngIf="node" [value]="node" selectionMode="checkbox" [(selection)]="selectedNode"> <ng-template let-node pTemplate="default"> <b>{{ node.data.description }}</b> </ng-template> </p-tree> –
There are 2 problems with your code :
node
property in your component class ;value
) ;Here are some fixes
Service :
Component :
Template (HTML) :