【问题标题】:Ag-Grid Header Component with AngularJS compiled template带有 AngularJS 编译模板的 Ag-Grid 标头组件
【发布时间】:2019-03-04 19:30:08
【问题描述】:

我想在我的 AngularJS (v1.6.8) 页面的网格中使用 Ag-Grid 标题组件。我可以使用this answer 使组件工作,但它似乎不像已弃用的 headerCellRenderer 那样编译 AngularJS。

如何让 Header 组件编译 AngularJS?

这里有一个基本的例子:https://embed.plnkr.co/mUmNL1/

【问题讨论】:

    标签: angularjs ag-grid


    【解决方案1】:

    您需要为此使用$compile 服务。

    getTemplate = function () {
      var str = $compile('<span ng-click="alertMsg()">{{getLabel()}}</span>')($scope)[0];
      return str;
    };
    

    看看这个 plunk:ag-grid angularjs custom header component

    此外,您需要根据以下示例对CustomerHeaderinit 函数进行一些更改:Angular 1.x and ag-Grid Components

    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);
    };
    

    【讨论】:

      猜你喜欢
      • 2017-07-13
      • 2020-08-24
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      相关资源
      最近更新 更多