It is a $scope
inside ag-grid
(笨蛋)
在调用之前ageCellRendererFunc
function ageCellRendererFunc(params) {
params.$scope.ageClicked = ageClicked;
eturn '<button ng-click="ageClicked(data.age)">Age</button>';
}
它初始化params
(4012):
RenderedCell.prototype.createParams = function () {
var params = {
node: this.node,
data: this.node.data,
value: this.value,
rowIndex: this.rowIndex,
colDef: this.column.colDef,
$scope: this.scope, // <----
context: this.gridOptionsWrapper.getContext(),
api: this.gridOptionsWrapper.getApi()
};
return params;
};
所以你可以使用controller as
module.controller("exampleCtrl", function($http) {
var vm = self;
/* ... */
}
带 vm 的柱塞 http://plnkr.co/edit/41vsiT9D0Bdi08mX
EDIT 1
这是一个plunker http://plnkr.co/edit/YS6YEATaq0lMFw4L使用 ag-grid 22.0.0
(Added agGrid.initialiseAgGridWithAngular1(angular)
)
这段代码很好:
function ageCellRendererFunc(params) {
params.$scope.ageClicked = ageClicked;
return '<button ng-click="ageClicked(data.age)">Age</button>';
}
正如你提到的$scope
与params
而不是你的控制器。您的控制器不使用$scope
根本不。这是ag-grid的定义。开发人员可以使用另一个变量 -bob
语法将是params.bob.ageClicked = ageClicked;