AngularJS: ¿Cómo acceder al ámbito desde la plantilla de celda ui-grid?


¿Cómo se accede a $scope desde una plantilla de celda ui-grid? Aquí está mi código de controlador:

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

Véalo en acción aquí: http://plnkr.co/edit/WYXeQShHWKDYDs4MIZnP?p=preview

Esperaría que el contenido de la celda mostrara "hola mundo", pero solo muestran "hola".

Author: John Slegers, 2015-01-24

1 answers

Según http://ui-grid.info/docs/#/tutorial/305_appScope, la cuadrícula tiene su propio ámbito isaloted, por lo que debe usar grid.appScope para acceder al ámbito de su aplicación. La solución es cambiar la plantilla de celda a:

  cellTemplate: '<div>{{ "hello " + grid.appScope.world() }}</div>'
 68
Author: tenfour,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-25 11:58:22