如何调用从-in角JS显示ngGrid一个按钮范围的方法 [英] How to call a scope method from a button displayed in ngGrid -in Angular js
问题描述
angular.module('harbinger').controller(
'Admin.UserlistController',
function($rootScope, $scope, $location, $http, userService)
{
// etc
$scope.gridOptions = {
// etc ,
enableRowSelection: false,
columnDefs: [
{field: 'userName', displayName: 'Username'},
{field: 'name', displayName: 'Name'},
{field: 'organization', displayName: 'Organization'},
{field: 'title', displayName: 'Title'},
{field: 'dateOfBirth', displayName: 'Date Of Birth'},
{field: 'controls', displayName: '', cellTemplate: '<div id="controls" ><a id="user-edit" onClick="editUser(\'{{row.entity.userName}}\')">Edit</a> | <a id="user-reset" data-ng-click="resetUser(\'{{row.entity.userName}}\')">Reset</a> | <a id="user-unlock">Un-lock</a></div>'}
]
};
用户复位的onclick我必须通过
onclick of user reset i have to pass the
userService.reset($scope.userData, function( data ) // success
{
// etc
}
我使用ngGrid,我试图调用从ngGrid显示一个按钮范围的方法。 -
i am using ngGrid, and i am trying to call a scope method from a button displayed in ngGrid. –
在点击我不能够执行此功能。
请给我的角度JS的方式来做到这一点。
on click i am not able to execute this function . Please give me angular js way to do this .
推荐答案
也许这是一个老问题,但我会回答。
Maybe it's an old question but I'll answer it.
ngGrid
创建一个孤立的范围,所以没有通过这样的事情让你的父母范围的方式:
ngGrid
creates an isolated scope so there is no way of getting to your parent scope via something like this:
-
$ parent.editUser('')
-
&LT; DIV NG控制器=AppCtrl作为CTRL&GT;&LT; DIV NG-格=选项&GT;&LT; / DIV&GT;&LT; / DIV&GT;
和ctrl.editUser('')
- 使用
$ scope.callback = {}; $ scope.callback.editUser =功能(){};
- >callback.editUser('')
)
$parent.editUser('')
<div ng-controller="AppCtrl as ctrl"><div ng-grid="options"></div></div>
andctrl.editUser('')
- by using
.
($scope.callback = {}; $scope.callback.editUser = function(){};
->callback.editUser('')
)
ngGrid
使用您的选项
中分离出来的范围内,这是提供给你的细胞/ rowTemplates
- 所以你可以做如下:
ngGrid
uses your options
in the isolated scope, which is available to your cell/rowTemplates
- so you can do as follows:
的Javascript控制器:
$scope.editUser = function(userName) {
...
};
$scope.options = {
data: 'data',
columnDefs: [{
field:'name',
displayName:'name',
cellTemplate: '<div ng-click="options.editUser(\'{{row.entity.userName}}\')">Edit</div>'
}],
editUser: $scope.editUser
}
HTML:
<div ng-grid="options"></div>
Plunker:
测试应用
这篇关于如何调用从-in角JS显示ngGrid一个按钮范围的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!