You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AG Grid Angular上下文菜单无法调用组件函数问题求助

AG Grid Angular上下文菜单无法调用组件函数问题求助

各位好,我在Angular项目里使用AG Grid的上下文菜单时,碰到了一个头疼的问题——没法正常调用组件里的函数,想请教下大家有没有解决办法。

先给大家看我的核心代码:

ngOnInit(): void {
  this.getContextMenuItems = (params) => this.getMenuItems(params);
}

deleteMenuItemEvent = (rowdata) => {
  window.alert("Test Test");
};

getMenuItems(
  params: GetContextMenuItemsParams
): (string | MenuItemDef)[] {
  var result: (string | MenuItemDef)[] = [
    {
      // custom item
      name: "Menu Item 1",
      action: () => this.deleteMenuItemEvent(params),
      cssClasses: ['red', 'bold'],
    },
    {
      // custom item
      name: "Menu Item 2",
      action: function () {
        this.deleteMenuItemEvent(params);
      }
    }
  ];
  return result;
}

现在点击菜单选项的时候,会抛出这个错误:
TypeError: Cannot read properties of undefined (reading 'deleteMenuItemEvent')

我之前试过一些相关的解决思路,但都没起作用,想问问社区的各位,除了常规方法外,还有什么其他可以尝试的方向吗?

备注:内容来源于stack exchange,提问作者user804401

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 09:43:15