I am using TreeView Component borrowed from Torgeir Helgevold's post or this Plunker. I try to call parents method from TreeView when is double click on any node but it works only for top node. Here is what I have so far Parents Component
@Component({
selector: 'hierarchy-mgmt',
template: ' <div class="accounts-container col col-lg-3 col-md-4 col-xs-12">
<h2>Managed Accounts</h2>
<tree-item-renderer [account]="commonNodeModel.rootNode"
(editing)="editStart($event)">
</tree-item-renderer>
</div>
',
providers: [TreeItemRendererComponent]
})
export class HierarchyMgmtComponent implements OnInit {
//... constructor and other code
ngOnInit(): void {
this.nodeService.getNodesForUser()
.then((rootNode: CustomerNode) => {
this.commonNodeModel.RootNode = rootNode;
this.commonNodeModel.SelectedNode = rootNode;
return this.nodeService.getNodeValidationDetails();
})
.then((nodeValidationDetails: NodeValidationDetails) => {
this.commonNodeModel.NodeValidationDetails = nodeValidationDetails;
this.hierarchyLoaded = true;
console.log(this.commonUserModel.usersForSelectedNode);
})
.catch(
Utils.callFailureWithResponseDataFunction((failureResponse: any, hasBeenDisplayedToUser: any) => {
this.notifyService.notifyUserIfNecessary(hasBeenDisplayedToUser, "There was a problem initialising this page. Please contact Support");
}));
}
editStart(node: CustomerNode) {
this.commonNodeModel.EditingNode = node;
}
// ... other code
}
TreeItemRenderer Component
@Component({
selector: 'tree-item-renderer',
template: `
<div class="node">
<span class="node-input" [ngClass]="getSelectedClass()" (dblclick)="edit(account)" (click)="spanSelected()"
title="{{account.name}}" [innerHtml]="account.name"></span>
<input type="text" class="editField" [ngModel]="account.name" placeholder="Enter an Account Name">
<ul class="node-list">
<li *ngFor="let account of account.children">
<tree-item-renderer [account]="account" (editing)="editStart($event)"></tree-item-renderer>
</li>
</ul>
</div>
`
})
export class TreeItemRendererComponent implements OnInit {
@Output()
editing: EventEmitter<any> = new EventEmitter<any>();
edit(node: any) {
this.editing.emit(node);
}
// ... other codes
}
The problem is that child node has referent to TreeItemRenderer component and not to HierarchyMgmtComponent. Guess in TreeItemRenderer component needs something like (editing)="parents.editStart($event)". Can anyone help please. Thank you.
In addition, I am aware of that HierarchyMgmtComponent component can be injected into TreeItemRenderer component, "which I have tried it and it is working", but it is not what I am looking for.