angularjs - 带有 AngularJS 编译模板的 Ag-Grid 标头组件
问题描述
我想在我的 AngularJS (v1.6.8) 页面的网格中使用 Ag-Grid 标题组件。我可以使用这个答案让组件工作,但它似乎不像已弃用的 headerCellRenderer 那样编译 AngularJS。
如何使 Header 组件编译 AngularJS?
有关基本示例,请参见此处:https ://embed.plnkr.co/mUmNL1/
解决方案
您需要为此使用$compile
服务。
getTemplate = function () {
var str = $compile('<span ng-click="alertMsg()">{{getLabel()}}</span>')($scope)[0];
return str;
};
看看这个 plunk:ag-grid angularjs custom header component
此外,您需要根据此示例对CustomerHeader
'init
函数进行一些更改:Angular 1.x 和 ag-Grid 组件
MakeHeaderComp.prototype.init = function (params) {
this.eGui = document.createElement('div');
this.eGui.innerHTML = '=> {{params.displayName}}';
// create and compile AngularJS scope for this component
this.$scope = $scope.$new();
$compile(this.eGui)(this.$scope);
this.$scope.params = params;
// in case we are running outside of angular (ie in an ag-grid started VM turn)
// we call $apply. we put in timeout in case we are inside apply already.
setTimeout(this.$scope.$apply.bind(this.$scope), 0);
};
推荐阅读
- microsoft-graph-api - Microsoft Graph API 是否可用于 Microsoft Teams 使用报告
- r - 为分配/分配问题设置线性程序
- google-apps-script - Google 表格触发器更新表中的值,但不会保持旧值不变
- java - java如何存储文字?
- docker - 为什么在使用 python:3.7-slim 时我的构建失败并显示“”?
- c - 当用户在 scanf() 中输入错误的数据类型时如何修复无限循环?
- asp.net-web-api - 为什么我的 MVC/Angular 应用程序在尝试在 prod 中启动时抛出“Microsoft.AspNet.TelemetryCorrelation not found”?
- python - Pandas/Python,df.duplicated 的 if 语句
- python - 调试要从终端运行的python应用程序
- php - 在刀片中执行 Foreach 时收到非对象错误