隐藏UI-Grid template based on condition in angular js 1

Hide UI-Grid template based on condition in angular js 1

If field 键我总是有布尔值。我想要的是如果值为 true 则显示单元格模板,否则将其隐藏。

columnDefs: [{
            displayName: 'Advanced',
            field: 'advanced',
            enableSorting: true,
            enableFiltering: true,
            enableColumnResizing: false,
            cellTemplate: 'scripts/components/profiles/tm/programs/datagrid/advancedCellTemplate.html',
            maxWidth: 108,
            filter: {
                type: uiGridConstants.filter.SELECT,
                selectOptions: controller.programsPackage
            }
        }]

我发现解决方案很简单,我只需要根据字段 advanced value

添加条件到单元格模板
'<div ng-if="row.entity.advanced">'

您可以像这样使用 angular.extend 或 Object.assign

const fields = [angular.extend({}, {
   displayName: 'Advanced',
   field: 'advanced',
   enableSorting: true,
   enableFiltering: true,
   enableColumnResizing: false,
   maxWidth: 108,
   filter: {
      type: uiGridConstants.filter.SELECT,
     selectOptions: controller.programsPackage
   }
 }, field ? {
     cellTemplate:  'scripts/components/profiles/tm/programs/datagrid/advancedCellTemplate.html'
} : null)]