angular ui grid错误:未找到:.ui-grid-header-cell .ui-grid-cell-contents

时间:2017-06-12 08:35:38

标签: javascript angularjs angular-ui-grid ui-grid

尝试查找导致seconD表不呈现并抛出以下错误的问题: VM16604 angular.js:13236错误:未找到:.ui-grid-header-cell .ui-grid-cell-contents

我正在使用使用:

https://www.npmjs.com/package/ui-grid-auto-fit-columns

http://ui-grid.info/

JS:

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pinning', 'ui.grid.autoFitColumns','ui.grid.resizeColumns']);

app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {

    $scope.gridOptions = {};

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
    .success(function(data) {
      $scope.gridOptions.data = [data[0]];

    });
  $scope.gridOptions.columnDefs = [

    { name:'eee' },
    { name:'age'  },
    { name:'address.street'}
  ];


  $scope.gridOptions2 = {};
    $scope.gridOptions2.data = [{'nameA':'contentA1','nameB':'contentB1'},{'nameA':'contentA2','nameB':'contentB2'}];
      $scope.gridOptions2.columnDefs = [{name:'nameA'},{name:'nameB'}];



console.log($scope.gridOptions);
console.log($scope.gridOptions2);
}]);

HTML:

<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="http://ui-grid.info/release/ui-grid.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
    <link rel="stylesheet" href="main.css" type="text/css">
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
  <link rel="stylesheet" href="https://npmcdn.com/angular-ui-grid@latest/ui-grid.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
  <script src="https://npmcdn.com/angular-ui-grid@latest/ui-grid.min.js"></script>
  <script src="https://npmcdn.com/ui-grid-auto-fit-columns@latest/dist/autoFitColumns.min.js"></script>
  </head>
  <body>

<div ng-controller="MainCtrl">
  <div>
  <div ui-grid="gridOptions"
        ui-grid-auto-fit-columns
        ui-grid-pagination
        ui-grid-resize-columns
        class="full-height"></div>

    <div ui-grid="gridOptions2"
        ui-grid-auto-fit-columns
        ui-grid-pagination
        ui-grid-resize-columns
        class="full-height"></div>      
        </div>
</div>


    <script src="app.js"></script>
  </body>
</html>

plnkr有错误: http://plnkr.co/edit/yXE3AuZEPwjlmlqpFTNq?p=preview

3 个答案:

答案 0 :(得分:1)

我检查了你的与它相关的&#34; ui-grid-auto-fit-columns&#34;在第二个gridOptions2中,一旦从html中删除,它将开始工作。

答案 1 :(得分:0)

似乎这是一个报告的问题,它通过不同步定义gridOptions而有一个解决方法....

https://github.com/Den-dp/ui-grid-auto-fit-columns/issues/10

答案 2 :(得分:-1)

   Now its working, try with following code, I have remove ui-grid-auto-fit-columns derective from your html div and also remove dependancy from module 'ui.grid.autoFitColumns'

    <div ng-controller="MainCtrl">
      <div>
      <div ui-grid="gridOptions"
            ui-grid-pagination
            ui-grid-resize-columns
            class="full-height"></div>

        <div ui-grid="gridOptions2"
            i-grid-auto-fit-columns
            ui-grid-pagination
            ui-grid-resize-columns
            class="full-height"></div>      
            </div>
    </div>


var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pinning',
'ui.grid.resizeColumns','ui.grid.selection', 'ui.grid.resizeColumns']);

app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {

    $scope.gridOptions = {};

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
    .success(function(data) {
      $scope.gridOptions.data = [data[0]];

    });
  $scope.gridOptions.columnDefs = [

    { name:'eee' },
    { name:'age'  },
    { name:'address.street'}
  ];


  $scope.gridOptions2 = {};
    $scope.gridOptions2.data = [{'nameA':'contentA1','nameB':'contentB1'},{'nameA':'contentA2','nameB':'contentB2'}];
      $scope.gridOptions2.columnDefs = [{name:'nameA'},{name:'nameB'}];



console.log($scope.gridOptions);
console.log($scope.gridOptions2);
}]);