结合ng-grid和ui.bootstrap.modal

时间:2014-04-02 06:16:57

标签: angularjs angular-ui-bootstrap ng-grid

我试图将ng-grid放在模态窗口(ui.bootstrap.modal)上。当网格放在主页面上时,一切正常。

但是当我把它放入

<script type="text/ng-template"...></script>

我得到以下内容:

  

&#34; TypeError:无法设置属性&#39; gridDim&#39;未定义&#34;。

是否有一些解决方法可以将ng-grid放在模态窗口上?

我的插件在这里:http://plnkr.co/edit/ctLF6j3WeqSvT3vEM40f?p=preview

1 个答案:

答案 0 :(得分:3)

http://plnkr.co/edit/SkqwlmfSM6jpgS9rR5Ad

var ModalInstanceCtrl = function ($scope, $modalInstance, items) {

$scope.gridOptions = { 
    data: 'myData',
    columnDefs: [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}, {field: 'remove', displayName:'', cellTemplate: removeTemplate}]
};
$scope.myData = [{name: "Moroni", age: 50},
                 {name: "Tiancum", age: 43},
                 {name: "Jacob", age: 27},
                 {name: "Nephi", age: 29},
                 {name: "Enos", age: 34}]; 
  $scope.items = items;
  $scope.selected = {
    item: $scope.items[0]
  };

  $scope.ok = function () {
    $modalInstance.close($scope.selected.item);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
};

模态使其自身的范围不是从您定义gridOptions的范围继承,如果找不到gridOptions来设置gridDim,则会发生此错误。