Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度:无范围编辑_Javascript_Angularjs_Angular Ui Grid - Fatal编程技术网

Javascript 角度:无范围编辑

Javascript 角度:无范围编辑,javascript,angularjs,angular-ui-grid,Javascript,Angularjs,Angular Ui Grid,我试图在gridOption.onREgisterApi函数中实现afterCellEdit函数。我没有在我的程序中使用$scope,正如指南中建议的那样 事实上,我的问题与此完全相同: 遗憾的是,没有人回答。 当我使用null作为一个答案时,我发现了一个错误 代码如下: vm.gridOptions.onRegisterApi = function(gridApi){ vm.gridApi = gridApi; vm.gridApi.edit.on.afterCellEdi

我试图在gridOption.onREgisterApi函数中实现afterCellEdit函数。我没有在我的程序中使用$scope,正如指南中建议的那样

事实上,我的问题与此完全相同: 遗憾的是,没有人回答。 当我使用null作为一个答案时,我发现了一个错误

代码如下:

  vm.gridOptions.onRegisterApi = function(gridApi){
    vm.gridApi = gridApi;
    vm.gridApi.edit.on.afterCellEdit(null,function(rowEntity, colDef, newValue, oldValue){
      alert("afterCellEdit");
    });
  };
这是我的错误:

typeError: Cannot read property '$on' of null
at Object.feature.on.(anonymous function) [as afterCellEdit]
谢谢

编辑:对于@SaurabhTiwari,这里是我的$scope.gridData替代方案

function onCustomerListComplete(data) {
    vm.gridOptions.data = data;
}


function OnError(reason) {
    $log.error(reason);
}

function activate() {
  customerService.getCustomerList()
            .then(onCustomerListComplete, OnError);
}

vm.gridOptions = { 
    enablePaginationControls: false,
    useExternalSorting: true,
    enableHorizontalScrollbar : uiGridConstants.scrollbars.NEVER,
    enableVerticalScrollbar : uiGridConstants.scrollbars.WHEN_NEEDED,
  columnDefs: [
  // will be modified once the data model is set
    { field: 'id', name: '', cellTemplate: 'content/customerList/rowEditor/customerList.rowEditor.editButton.html', width: 34 },
    { name: 'customerNumber', },
    { name: 'customerName' },
    { name: 'city' },
    { name: 'creditLimit' },
    { name: 'postalCode' },
  ]
};

在这里提供一些帮助可能已经晚了,您可能已经找到了解决方案。但是我想用下面的代码来解释你的情况

function (scope, handler, _this) {
            if ( scope !== null && typeof(scope.$on) === 'undefined' ){
              gridUtil.logError('asked to listen on ' + featureName + '.on.' + eventName + ' but scope wasn\'t passed in the input parameters.  It is legitimate to pass null, but you\'ve passed something else, so you probably forgot to provide scope rather than did it deliberately, not registering');
              return;
            }
            var deregAngularOn = registerEventWithAngular(eventId, handler, self.grid, _this);

            //track our listener so we can turn off and on
            var listener = {handler: handler, dereg: deregAngularOn, eventId: eventId, scope: scope, _this:_this};
            self.listeners.push(listener);

            var removeListener = function(){
              listener.dereg();
              var index = self.listeners.indexOf(listener);
              self.listeners.splice(index,1);
            };

            //destroy tracking when scope is destroyed
            if (scope) {
              scope.$on('$destroy', function() {
                removeListener();
              });
            }


            return removeListener;
          }
这是来自ui网格Api的原始代码。您可以在库中或从应用程序的适当范围中搜索它,您可以尝试执行以下操作:
$scope.gridApi.edit.on.afterCellEdit.toString()

这里的要点是,这个函数显式地需要一个作用域或null。因此,您确实需要将作用域传递给此侦听器

您在问题中提到的在代码中未使用
$scope
的观点有些模糊。如果您有控制器,则始终存在关联的
范围
。角度几乎与范围有关(至少角度1是)


参考的指导原则是,您应该避免将所有内容堆积在
$scope
上。指南还说,你应该只在听和看的时候使用
$scope
,这正是这里的情况

我不确定你指的是哪些指南。但在我看来,
$scope
需要在这里查看
编辑框上的更改。同样可以从您收到的错误中破译出来,因为如果没有Angular的开发人员John papa提供的
$scope
@SaurabhTiwari,您的数据绑定在哪里。您对
$scope.gridData={data:dataList}
有什么选择。我怀疑vm.gridData在这种情况下不起作用,它确实起作用了。我没有在我的问题中添加它,因为它工作正常,不会引起任何问题。我将添加它作为编辑。感谢您的更新。我现在知道它是如何工作的了,但是如果它是一个
$on
侦听器,那么它只会在
$scope
上被激发。如果我找到办法,我会设法回去的