gpt4 book ai didi

javascript - AngularJS:ng-click 在 ui-grid cellTemplate 中不起作用

转载 作者:行者123 更新时间:2023-12-01 03:39:37 25 4
gpt4 key购买 nike

我又来了,有 Angular 问题。

我的 HTML 中有一个网格,它只是一条线。

我正在复制粘贴 Controller 。

app.controller('PanelController', function ($scope,  $compile, uiGridConstants){

var actionTemplate = '<div class="ui-grid-cell-contents"><img class="addNotes" src="images/button/detail.gif" ng-click="dettaglio(row.entity)" /></div>';

$scope.dettaglio = function(ritornoSearch, inspect) {
console.log("make it function");
};

columnDefs: [
{ field: 'azioni', enableFiltering: false, width: 85, enableSorting: false, enableColumnMenu: false, cellTemplate: actionTemplate, displayName: 'Azioni'},
{ field: 'codeSubInstaller', headerCellClass: $scope.highlightFilteredHeader },
{ field: 'nomeSubInstaller', headerCellClass: $scope.highlightFilteredHeader },
{ field: 'cognSubInstaller', headerCellClass: $scope.highlightFilteredHeader },
{ field: 'codeFiscaleSubInstaller', headerCellClass: $scope.highlightFilteredHeader },
{ field: 'descStato' , headerCellClass: $scope.highlightFilteredHeader }
]
};

问题是:当我在浏览器中打开它时,图像不会显示为可点击。如果我尝试单击它,它甚至不会向我提供 console.log。

我错过了什么?

最佳答案

就像http://ui-grid.info/docs/#/tutorial/305_appScope中记录的那样做即可并比较这个 runnable plnkr demo 与您的解决方案。

$scope.grid.appScope is available in all templates that the grid uses. In a template, you access the scope using grid.appScope property

<小时/>

这样,您需要将模板更改为正确的语法:ng-click="grid.appScope.dettaglio(row)":

 var actionTemplate = '<div class="ui-grid-cell-contents"><img class="addNotes" src="images/button/detail.gif" ng-click="grid.appScope.dettaglio(row)" /></div>';
<小时/>

带有 ui-grid 的 AngularJS 应用示例:

var app = angular.module('app', ['ngTouch', 'ui.grid']);

app.controller('MainCtrl', ['$scope', '$log', '$http', function ($scope, $log, $http) {

$scope.dettaglio = function (row) {
console.log(row);
alert('inside');
};

$scope.gridOptions = {};

$scope.gridOptions.columnDefs = [
{name: 'name'},
{name: 'gender'}, {
name: 'ShowScope',
cellTemplate: '<button class="btn primary" ng-click="grid.appScope.dettaglio(row)">Click Me</button>'
}
];

$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json').success(function (data) {
$scope.gridOptions.data = data;
});

}]);

关于javascript - AngularJS:ng-click 在 ui-grid cellTemplate 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43997067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com