TypeError: XXX undefined with AngularJS $inject Property annotation

TypeError: XXX undefined with AngularJS $inject Property annotation

Angular UI 网格获取单元格值

我正在使用 angular 网格 ui,我正在尝试使用 getCellValue 根据行和列获取单元格的值。

我遇到错误

无法获取 属性 未定义或空引用的“$$undefined”

如何根据行和列从单元格中获取值?

angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid','ui.grid.resizeColumns','ui.grid.pinning','ui.grid.grouping',
    'ui.grid.moveColumns','ui.grid.exporter','ui.grid.selection','ui.grid.selection', 'ui.grid.cellNav']).controller('MainCtrl', MainCtrl);

    MainCtrl.$inject = ['$http', 'uiGridConstants','$interval','$scope'];
    
    function MainCtrl($http, uiGridConstants,$scope) {
        var vm = this;
        vm.gridOptions = { //vm
          exporterMenuCsv: true,
          enableGridMenu:true,
          onRegisterApi: function(gridApi){
            vm.gridApi = gridApi; //vm
          }
        };
    
        $http.get('/getProjects')
          .then(function(response) {
            //Loop through the response
            //If the vaule is 255 set the color of the cell to ect.
            var responseData = response.data
              console.log(vm.gridApi.grid.getCellValue(1,1));
              //console.log(responseData[i].Iuk)
         });
      }

注入数组与函数参数不匹配:

MainCtrl.$inject = ['$http', 'uiGridConstants','$interval','$scope'];

function MainCtrl($http, uiGridConstants,$scope) {

来自文档:

$inject Property Annotation

When using this type of annotation, take care to keep the annotation array in sync with the parameters in the function declaration.

— AngularJS Developer Guide - Dependency Injection

使用 Implicit Annotation. Tools like ng-annotate 可以避免此问题,让您在应用中使用隐式依赖注释并在缩小之前自动添加数组注释。