0

I want to add code to a function that is inside of ui-grid. I do not want to edit the existing code. How can I add code to an existing function, in angular, that does not edit the original code?

I tried using the concept from Adding code to a javascript function programmatically but I couldn't get it working.

Community
  • 1
  • 1
fauverism
  • 1,970
  • 3
  • 33
  • 59

1 Answers1

1

You can use jQuery to find the scope and the function and modify it:

var $scope = $('[ng-click="paginationApi.nextPage()"]').scope();
var original_function = $scope.paginationApi.nextPage;
$scope.paginationApi.nextPage = function() {
    // do some stuff
    original_function.apply(this, arguments);
};
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • seems kind of strange to me that you're creating the var $scope and the paginationApi isn't available on angular's $scope. – fauverism May 20 '15 at 17:05
  • @fauverism If you created ui-grid it's probably different inner scope, so you need to find it first. – jcubic May 21 '15 at 07:41