不会触发功能我已经创建了一个plunker这里:NG单击控制器
当我在UI格在天视图中单击单元格,然后什么也没有发生。我期望的是测试功能被执行并且一个警告显示为文本'test',但事实并非如此。
这是怎么回事错在这里?
多数民众赞成在UI网3.0最新版本的HTML电池模板:
HTML
<div ng-click="test()" ng-switch="row.entity[row.grid.columns.indexOf(col)].isPeriod">
<div ng-switch-when="true">
<tabset>
<tab>
<tab-heading>
<i class="glyphicon glyphicon-book"></i>
</tab-heading>period id:
{{ row.entity[row.grid.columns.indexOf(col)].id}}
</tab>
<tab select="alertMe()">
<tab-heading>
<i class="glyphicon glyphicon-bell"></i>
</tab-heading>
{{row.entity[row.grid.columns.indexOf(col)].content}}
</tab>
</tabset> <!-- PeriodTemplate -->
</div>
<div ng-switch-when="false">
<div>Hello empty template</div>
</div> <!-- EmptyPeriodTemplate -->
</div>
控制器:
'use strict';
angular.module('projectplanner').controller('DateplannerDayController', function ($scope, $state) {
var columnHeaderDates = ['col1','col2','col3','col4','col5','col6','col7']
$scope.columns = createColumnHeaders(columnHeaderDates);
var data = [{isPeriod: true, id: 10, rowNumber: 1},{isPeriod: false, id: 11, rowNumber: 2}]
$scope.test = function()
{
alert('test');
};
$scope.gridOptions = {
rowHeight: 200,
data: data,
enableSorting: false,
enableColumnMenu: false,
columnDefs: $scope.columns,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.addRowHeaderColumn(
{ name: 'rowHeaderCol',
displayName: '',
width: 100,
cellTemplate: '<div>row header template</div>'
});
}
};
function createColumnHeaders(columnHeaders) {
var columnDefinitions = [];
for (var i = 0; i < columnHeaders.length; i++) {
var column = {
name: columnHeaders[i],
cellTemplate: 'lessonplanner.day.celltemplate.html',
field: i + 'x'
}
columnDefinitions.push(column);
}
return columnDefinitions;
}
});
use externalScopes。看到我的答案在这里:http://stackoverflow.com/questions/26621598/angular-ui-grid-events-in-cell-header-not-firing/26628361#26628361 – mainguy 2014-11-05 12:30:03
@mainguy这与externalScopes做什么?没有外部范围。 ui-grid的tut侧面的ng-click样例与我一样,没有外部范围,就是做同样的事情。嗯......这是奇怪的,我可以发誓我已经看到这个ng-click在单元模板上工作,但ui-grid说:“UI-Grid使用隔离作用域,所以不能从行或单元格模板“。好吧,我需要一个外部范围!谢谢哥们! – Pascal 2014-11-05 16:27:53
目前,ui-grid的版本,教程和手册都是一团糟。我也认为它不久前没有外部范围。希望这个测试很快就会结束。顺便说一句:你在那里建造的令人印象深刻的布拉克尔! – mainguy 2014-11-06 07:43:24