Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Angularjs grid.appScope不适用于ui网格_Angularjs_Angular Ui Grid - Fatal编程技术网

Angularjs grid.appScope不适用于ui网格

Angularjs grid.appScope不适用于ui网格,angularjs,angular-ui-grid,Angularjs,Angular Ui Grid,想要从我的自定义cellTemplate访问函数。为此,我使用grid.appScope。代码如下: $scope.test = function(){ alert('a'); }; columnDefs: [ { field: 'name', displayName: 'Name', cellTemplate: '<div ng-click="grid.appScope.test()">ABCDEFGH</div>' },

想要从我的自定义cellTemplate访问函数。为此,我使用grid.appScope。代码如下:

$scope.test = function(){
    alert('a');
  };

columnDefs: [
      { field: 'name',      displayName: 'Name', cellTemplate: '<div ng-click="grid.appScope.test()">ABCDEFGH</div>' },
      { field: 'id',      displayName: 'ID' }
]
$scope.test=函数(){
警报(“a”);
};
columnDefs:[
{字段:'name',显示名称:'name',单元格模板:'ABCDEFGH'},
{字段:'id',显示名称:'id'}
]

有人能告诉我上面的代码有什么问题吗?

我遇到了同样的问题,并且能够解决。在我的情况下,我们将网格作为指令,因为它无法识别测试函数。要做到这一点,只需使用$parent scope

像这样

grid.appScope.$parent.test();

你在哪里调用这个函数,现在还不清楚。整个代码都写在一个控制器中。函数“test()”是从cellTemplate调用的。这个答案帮助我理解了作用域是如何工作的。我试图访问grid.appScope.$ctrl.function()中的函数。我推荐浏览器扩展AngularJS Batarang,这样您就可以可视化模型树。