[英]Angular UI-Grid: In a cell template, how to access the value from a different field/cell
[英]AngularJS : How to access scope from ui-grid cell template?
如何從ui-grid單元模板訪問$scope
? 這是我的控制器代碼:
app.controller('MainCtrl', ['$scope', function ($scope) {
// i want to reference this from a cell template.
$scope.world = function() { return 'world'; };
$scope.gridOptions = {
data: [
{ id: "item1" },
{ id: "item2" }
],
columnDefs: [
{
field: 'id',
// world() is never called and is not displayed.
cellTemplate: '<div>{{ "hello " + world() }}</div>'
}]
};
}]);
請在此處查看: http : //plnkr.co/edit/WYXeQShHWKDYDs4MIZnP?p = preview
我希望細胞內容顯示“你好世界”,但他們只是顯示“你好”。
根據http://ui-grid.info/docs/#/tutorial/305_appScope ,網格有自己的isaloted范圍,因此您需要使用grid.appScope
來訪問您的應用程序范圍。 解決方案是將單元格模板更改為:
cellTemplate: '<div>{{ "hello " + grid.appScope.world() }}</div>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.