0

I have an array defined in slickgrid which captures the rows which are edited in the grid using OnCellChange event. I want to access this array in my angularjs Controller so that I can send the edited rows to backend. I have already searched for this question and I got to know that I need to use $window in my controller to access global js variable. But it's not working for me. I have read this How to access global js variable in AngularJS directive and this http://code.angularjs.org/1.1.5/docs/api/ng.$window

Infact in 2nd link(above) , many people have commented that it's didn't work for them either. Can anyone please tell me what am I missing?

Slick_grid.js

var editedRows = [];
    grid.onCellChange.subscribe(function(e , args){
      var item = args.item;
      for( i=0;i<editedRows.length; i++)
            {
             if(item.employeeId == editedRows[i].employeeId)
             {
                 editedRows.splice(i , 1 , item);
                 return;

             }
                else
             {
                 editedRows.push(item);
                 return;
             }
            }
    });

controller.js

myApp.controller('SubmitController' ,
    ['$scope' ,'$window', function($scope , $window)    {
     alert($window.editedRows);
     $scope.editedRows  =  $window.editedRows;

    }]);
Cœur
  • 37,241
  • 25
  • 195
  • 267
user911
  • 1,509
  • 6
  • 26
  • 52

1 Answers1

0

I think the editedRows may have been defined within a function scope (javascript) and hence not accesible outside.

If editedRows is your own variable you can try

window.editedRows = [];

Not a good solution though.

Chandermani
  • 42,589
  • 12
  • 85
  • 88
  • Thank you so much!! The issue was that my variable was defined inside a function scope. I just moved it outside function scope and it worked. – user911 Jan 31 '14 at 16:17
  • sorry can't upvote your answer. I don't have enough credits to do that. – user911 Jan 31 '14 at 16:31