3

Wanted to access a function from my custom cellTemplate. For that, i am using grid.appScope. Following is the code :

$scope.test = function(){
    alert('a');
  };

columnDefs: [
      { field: 'name',      displayName: 'Name', cellTemplate: '<div ng-click="grid.appScope.test()">ABCDEFGH</div>' },
      { field: 'id',      displayName: 'ID' }
]

Can anyone tell me what is the issue with the above code ?

2
  • Where are you calling this function and it is still unclear. Commented Sep 23, 2015 at 13:08
  • Entire code is written in a controller. Function "test()" is called from the cellTemplate. Commented Sep 23, 2015 at 13:11

1 Answer 1

4

I have face the same problem and able to resolve it in my case we have made the grid as directive in that it is not able to recognize the test function. In order to do that just use $parent scope

like this

grid.appScope.$parent.test();
Sign up to request clarification or add additional context in comments.

1 Comment

this answer has helped me understand how the scope works. I was trying to access a function in grid.appScope.$ctrl.function(). I recommend the browser extension AngularJS Batarang so you can visualize the model tree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.