如何动态更新 ng2-smart-table 的自定义部分?

How to update ng2-smart-table's custom part dynamically ?

在我的 angular 6 应用程序中,我使用了 ng2-smart-table。现在我需要根据访问权限显示和隐藏自定义操作功能。

我可以管理 addedirdelete 部分。为此,我还放置了一些自定义图标以提供额外功能。

custom: [            
  { name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' },
  { name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },
  { name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' },
  { name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' },
]

现在我需要根据权限来管理这个东西。

那么我该如何启用和禁用这些图标。

注意:我可以在每一行应用css然后隐藏图标,但我需要做一次而不是每一行。

您可以在自定义数组中添加图标的同时添加图标...

试试这个方法

if(access){     // Set you access condition
     this.settings.custom.push('{ name: 'up', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-true-icon">' }');
     this.settings.custom.push('{ name: 'up-cancel', title: '<img src="/pathOfIcon" class="tableIcon up-arrow-cancel-icon">' },');
}else{
    this.settings.custom.push(' { name: 'down', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-true-icon">' }');
    this.settings.custom.push('{ name: 'down-cancel', title: '<img src="/pathOfIcon" class="tableIcon down-arrow-cancel-icon">' }');
}  

这是添加图标的简单方法...因为 custom 是数组,所以您可以将图标放入其中...

希望这对您有所帮助...:)