Angular UI 网格:如何将 HTML 与 cellTemplate 绑定,并动态构建 HTML ng-click 适用的

Angular UI Grid: How to bind HTML with the cellTemplate, AND dynamically build HTML that ng-click works on

这是应要求提供的 plunker- http://plnkr.co/edit/tIkBFO?p=preview

我正在使用 controllerAs 模式。我一直在使用带有过滤器 ($sce) 的单元格模板进行清理,然后构建 HTML。对于我的生活,我无法让 ng-click 注册到我的控制器。

我可以将单元格模板更改为 cellTemplate:'<button ng-click="grid.appScope.user.delete(\'works!\')">X</button>'-> 这可行。

有没有办法在不使用单元格模板的情况下仍然访问控制器?详细信息列是我遇到问题的地方。

感谢阅读!

相关问题- https://github.com/angular-ui/ui-grid/issues/4116

https://github.com/angular-ui/ui-grid/issues/4886

这是代码-

        var user = this;

        user.gridDefs = [{
                            displayName: 'User ID',
                            name: 'userId',
                            width: "10%"
                        }, {
                            name: 'firstName',
                            width: "15%"
                        }, {
                            name: 'lastName',
                            width: "15%"
                        }, {
                            name: 'email',
                            cellTemplate: '<div ng-bind-html="COL_FIELD |trustedclean"></div>',
                            width: "25%"
                        }, {
                            name: 'username',
                            width: "15%"
                        }, {
                            name: 'details',
                            cellTemplate:'<div ng-bind-html="COL_FIELD |trustedclean"></div>'
                            width: "20%"
                        }, ];

user.gridData = _.map(dataFromSvc.users, function(user) {
                    var buildDetailsString = buildDetails(user.uid);
                    var object = {
                        'userId': user.Id,
                        'firstName': user.firstName,
                        'lastName': user.lastName,
                        'email': '<a href=\"mailto:' + user.primaryEmail + '\">' + user.primaryEmail + '</a>',
                        'username': user.uid,
                        'details': '<div><a href=\"#/viewuser/'+user.uid+'/true\">View</a>/<a ng-click=\"user.deleteUser('+user.uid+')\">Delete</a></div>'
                    return object;
                });

    user.deleteUser = function(uid) {
                    console.log(uid);

                };

这里是 HTML-

<div id="grid2" ui-grid="{ data: user.gridData, columnDefs:user.gridDefs}" class="grid"></div>

回答我自己的问题-

不要清理,并在 ui-grid 上使用 ng-bind。使用模板来管理您的单元格。这就是我所做的。

cellTemplate:dynamicTemplate

这足以绑定包含字符串

的html
{ field: 'message', displayName : 'Message Description', cellTemplate: '<div ng-bind-html="COL_FIELD"></div>' }