AngularJS:如何从UI的网格单元模板访问范围是什么? [英] AngularJS : How to access scope from ui-grid cell template?

查看:127
本文介绍了AngularJS:如何从UI的网格单元模板访问范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何一次访问 $范围从UI的网格单元模板?这里是我的控制器code:

How does one access $scope from a ui-grid cell template? Here's my controller code:

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>'
    }]
  };
}]);

看到它在这里的行动:
<一href=\"http://plnkr.co/edit/WYXeQShHWKDYDs4MIZnP?p=$p$pview\">http://plnkr.co/edit/WYXeQShHWKDYDs4MIZnP?p=$p$pview

我希望单元格的内容显示的Hello World,但他们只是显示你好。

I would expect cell contents to show "hello world", but they just show "hello".

推荐答案

好吧,我想通了。据<一个href=\"http://ui-grid.info/docs/#/tutorial/305_appScope\">http://ui-grid.info/docs/#/tutorial/305_appScope,电网都有自己的isaloted范围,所以你需要使用 grid.appScope 来访问你的应用范围。解决的办法是在细胞模板更改为:

Ok I figured it out. According to http://ui-grid.info/docs/#/tutorial/305_appScope, the grid has its own isaloted scope, so you need to use grid.appScope to access your application scope. The solution is to change the cell template to:

  cellTemplate: '<div>{{ "hello " + grid.appScope.world() }}</div>'

这篇关于AngularJS:如何从UI的网格单元模板访问范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆