I'm trying to call a method on the menu onclick event as follows, but it gives an error.
component.ts
loadWorkSpace(WorkSpaceName: string, QNameSpaceId: number, QEnvironemntId: number, QWorkSpaceId: number) {
this._qWorkSpaceFilterServiceProxy
.getAll(QWorkSpaceId, null, 0, 1000)
.subscribe((result) => {
filterItemList = _map(result.items, function (qWSFilter) {
return {
label: qWSFilter.qWorkSpaceFilter.workspaceFilterName, command: (event: Event) => this.consoleMsg()
};
});
this.items = [
{
label: 'Applications',
items: itemList
},
{
label: 'Filters',
items: filterItemList
}
];
});}
consoleMsg() {
console.log("test");
}
Error: Console error message
I'm sorry for my bad english.
I was having trouble accessing the 'this' token because of the '_map' method I used.
Doing it this way fixed it:
filterItemList = result.items.map((qWSFilter) => {
return {
label: qWSFilter.qWorkSpaceFilter.workspaceFilterName, command: (event) => { this.consoleMsg() }
};
});