首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >TypeError:未使用AngularJS $inject属性批注定义XXX

TypeError:未使用AngularJS $inject属性批注定义XXX
EN

Stack Overflow用户
提问于 2018-06-05 02:25:03
回答 1查看 73关注 0票数 1

Angular UI Grid Get Cell Vaule

我正在使用角度网格ui,我正在尝试使用getCellValue获得基于行和列的单元格的值。

我得到了错误

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

如何从基于行和列的单元格获取Vaule值?

代码语言:javascript
复制
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)
         });
      }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-05 07:37:39

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

代码语言:javascript
复制
MainCtrl.$inject = ['$http', 'uiGridConstants','$interval','$scope'];

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

从文档中:

$inject属性批注

在使用这种类型的注释时,要注意使注释数组与函数声明中的参数保持同步。

— AngularJS Developer Guide - Dependency Injection

这个问题可以通过使用Implicit Annotation来避免。像ng-annotate这样的工具可以让你在你的应用中使用隐式依赖注解,并在最小化之前自动添加数组注解。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50686646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档