【发布时间】:2021-06-23 19:59:58
【问题描述】:
我想实现一个使用Menu Model API 的primeng ContextMenu。 MenuItem 对象有一个名为“command”的属性,据我了解,它是一个函数。
由于我的后端通过 HTTP 调用发送可用的上下文菜单项,因此我需要在接收数据时在前端分配此功能。
代码按预期编译和工作,但是我的 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;
ctxAction 是 MenuItem 类型,当我将鼠标悬停在变量上时确认。
分配如下:
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');
}
我在这里做错了什么?
提前非常感谢!
【问题讨论】:
标签: angular typescript contextmenu primeng