我想做一些我不知道是否可能的事情
HTML
<!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <Meta charset="utf-8"> <title>Custom Plunker</title> <link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" /> <link rel="stylesheet" type="text/css" href="style.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script> <script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script> <script type="text/javascript" src="main.js"></script> </head> <body ng-controller="MyCtrl"> <div class="gridStyle" ng-grid="gridOptions"></div> </body> </html>
JS
// main.js var app = angular.module('myApp',['ngGrid']); app.controller('MyCtrl',function($scope) { $scope.myData = [{name: "Moroni",age: 50},{name: "Tiancum",age: 43},{name: "Jacob",age: 27},{name: "Nephi",age: 29},{name: "Enos",age: 34}]; $scope.gridOptions = { data: 'myData',cellTemplate:'<div class="ngCellText" ><a ng-click="foo()">{{row.getProperty(col.field)}}</a></div>' } $scope.foo = function() { alert(''); }; });
我想在ng-grid中的一行上放置一个ng-click事件,我已经把这个想法环顾四周,但我真的不明白它是否可能,如果是这样的话,如果这是正确的方式去做.
在这段代码中,这似乎对我有好处,应用程序不会启动警报,任何建议或想法?
这是plunker http://plnkr.co/edit/U6wdWTAV30HRhJk8xFPA?p=preview
这些定义对我有用:
原文链接:https://www.f2er.com/angularjs/143546.html$scope.gridOptions = { data: 'myData',columnDefs: [{ field: 'name',displayName: 'Name',cellTemplate: '<div ng-click="foo()" ng-bind="row.getProperty(col.field)"></div>' },{ field: 'age',displayName: 'Age',cellTemplate: '<div ng-click="foo()" ng-bind="row.getProperty(col.field)"></div>' } ] };
查看分叉的Plunker here