ng-click在ag-grid单元内部不起作用 [英] ng-click not worked inside ag-grid cell
本文介绍了ng-click在ag-grid单元内部不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用ag-grid,我需要在单元格中添加一些自定义链接,并想在其上调用ng-click函数.这是我的代码
i am working with ag-grid and i need to add some custom links in a cell and want to call ng-click function on it. Here is my code
var columnDefs =[
{headerName: "ID", field: "id"},
{headerName: "Template Name", field: "user_template_name"},
{headerName: "Screen", field: "screen_name"},
{headerName: "Last Uploaded", field: "created_at"},
{headerName: "Manage", cellRenderer: createCustomLinks }
];
var gridOptions = {
angularCompileRows:true,
columnDefs: columnDefs,
rowData: null,
enableSorting: true,
enableColResize: true,
};
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
gridOptions.columnApi.setColumnVisible('id', false);
gridOptions.api.sizeColumnsToFit();
function createCustomLinks(params) {
var cellHtml = '<a ng-click="openTemplateID('+params.data.id+')">Open</a>';
var domElement = document.createElement("span");
domElement.innerHTML = cellHtml;
params.$scope.openTemplateID = function(id){
console.log(id);
}
return domElement;
};
我遇到了以下错误
TypeError: _this.$scope is null
setTimeout(function () { _this.$scope.$apply(); }, 0);
ag-grid.js (line 7415, col 39)
Error: this.parentScope is null
RenderedRow</RenderedRow.prototype.createChildScopeOrNull
如果我做错了什么,请指导我.谢谢.
Please guide me if i am doing something wrong. Thank you.
推荐答案
我曾经遇到过这个问题.我们需要在网格选项中定义它.将 angularCompileRows 设置为true可以为我解决此问题
I had this issue once. We need to define it in the grid options. Setting angularCompileRows to true resolved this issue for me
$scope.gridOptions = {
columnDefs: $scope.columnDefs,
rowData: $scope.rowData,
// all other options
angularCompileRows: true
};
这篇关于ng-click在ag-grid单元内部不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文