如何将函数作为数据传递给 angular 中的另一个模块组件?

How to pass function as data to another module component in angular?

我有一个包含一些内容和导航的主模块

我在主模块中有子模块(延迟加载),它应该给我导航项。

我做了一个传递数据的服务:

const navItems = [  
  { text: 'Add', icon: faUser,, function: 'AddDLevels()'},
  { text: 'Create D1', icon: faUser, function: 'toggleCreateD1()'},
  { text: 'Create D2', icon: faUser, function: 'toggleCreateD2()'},
  { text: 'Push DS78', icon: faUser, function: 'pushDS()'}
];
this.consoleNav.setNavItems(navItems);

如何使这些功能发挥作用? 我想单击导航按钮,它应该反映在子模块组件中。

与其将函数作为字符串传递,不如传递对函数的引用,例如:

const navItems = [  
  { text: 'Add', icon: faUser, function: () => AddDLevels()},
];

然后您只需在点击处理程序或诸如此类的东西中调用该函数

item.function()