I am currently working on implementing a primeng ContextMenu using the Menu Model API. Within the MenuItem object, there is a property named "command" which, to my understanding, should be a function.
As I am receiving the available context menu items from the back-end through an HTTP call, I need to assign this function in the front-end upon data reception.
Although the code compiles and functions correctly, I am encountering an error message in my IDE:
ERROR in src/app/protected/workbench/sidebar/sidebar.component.ts:61:21 - error TS2339: Property 'command' does not exist on type 'never'.
61 ctxAction.command = this.execCtxAction;
Upon hovering over the variable with my mouse, I have confirmed that ctxAction is indeed of type MenuItem.
The assignment process looks like this:
public getFavourites() {
let url = "http://localhost:8081/api/fav/all";
this.http.get<Fav[]>(url).subscribe(
res => {
for (const resItem of res) {
let ctxActionList = resItem.dtoEntity.ctxActionList;
// the variable ctxAction is of type MenuItem[]
for (let ctxAction of ctxActionList) {
ctxAction.command = this.execCtxAction;
}
}
this.fav = res;
},
err => { alert("there is an error") }
);
}
execCtxAction(): void {
console.log('execute context action');
}
Could someone please point out what I might be doing wrong here?
Thank you in advance!