uiGridConstants未定义(但它们被传入控制器)

时间:2018-02-21 17:00:14

标签: angularjs angular-ui-grid

尝试在uigrid中获取我的列的值的聚合。我已将uiGridConstants注入控制器,并且在我的app.js中我有ui.grid ...但是,无论我做什么,uiGridConstants都会被传递回未定义。有人知道吗?

GridOptions

$scope.gridOptions = {
  infiniteScrollRowsFromEnd: '50',
  selectionRowHeaderWidth: '100',
  enableColumnMenus: false,
  rowHeight: '45',
  enableFiltering: true,
  columnDefs: [
    { field: 'name', name: 'Name', width: '*', cellTemplate: '<div class="ui-grid-cell-contents"><a ui-sref="contacts-profile({ id: row.entity.id })">{{COL_FIELD}}</a></div>'},
    { field: 'type', name: 'Type', width: '*' },
    { field: 'status', name: 'Status', width: '*' },
    { field: 'premium', name: 'Premium', width: '*', cellTemplate: '<div class="ui-grid-cell-contents">${{COL_FIELD}}</div>', aggregationType: uiGridConstants.aggregationTypes.count },
    { field: 'commission', name: 'Comission', width: '*', cellTemplate: '<div class="ui-grid-cell-contents">${{COL_FIELD}}</div>' },
    { field: 'created_by', name: 'Created by', width: '*' }
  ]
};

注射器

constructor($scope, $location, CognitoService, $http, uiGridConstants, uiGridGroupingConstants) {

PoliciesCtrl.$inject = ['$scope', '$location', 'CognitoService', '$http', '$q', '$timeout', '$filter', 'uiGridConstants', 'uiGridGroupingConstants'];

如果我console.log uiGridConstants我得到了

ƒ $Q(resolver) {
        if (!isFunction(resolver)) {
          throw $qMinErr('norslvr', 'Expected resolverFn, got \'{0}\'', resolver);
        }

        var promise = new Promise();

        function resolveFn(v…

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

constructor($scope, $location, CognitoService, $http,  $q, $timeout, '$filter', uiGridConstants, uiGridGroupingConstants) {

PoliciesCtrl.$inject = ['$scope', '$location', 'CognitoService', '$http', '$q', '$timeout', '$filter', 'uiGridConstants', 'uiGridGroupingConstants'];

参数的数量必须相同,并且在注入和构造函数中的顺序相同。