How to call a scope method from a button displayed in ngGrid -in Angular js

后端 未结 1 347
误落风尘
误落风尘 2021-01-07 13:57
angular.module(\'harbinger\').controller(
   \'Admin.UserlistController\',  
   function($rootScope, $scope, $location, $http, userService)
   {
      // etc
      $         


        
1条回答
  •  执念已碎
    2021-01-07 14:53

    Maybe it's an old question but I'll answer it.

    ngGrid creates an isolated scope so there is no way of getting to your parent scope via something like this:

    1. $parent.editUser('')
    2. and ctrl.editUser('')
    3. by using . ($scope.callback = {}; $scope.callback.editUser = function(){}; -> callback.editUser(''))

    ngGrid uses your options in the isolated scope, which is available to your cell/rowTemplates - so you can do as follows:

    Javascript Controller:

    $scope.editUser = function(userName) {
        ...
    };
    
    $scope.options = {
        data: 'data',
        columnDefs: [{
            field:'name', 
            displayName:'name', 
            cellTemplate: '
    Edit
    ' }], editUser: $scope.editUser }

    HTML:

    Plunker: Test app

    0 讨论(0)
提交回复
热议问题