Skip to content

Commit

Permalink
Fixes #394, Array.forEach() assumed to exist
Browse files Browse the repository at this point in the history
IE8 doesn't support the Array prototype's forEach() method, and I used it
in grid.initTemplates(). I've fixed this to use angular.forEach() instead
and added a test to catch calls in initTemplates() to
Array.prototype.forEach()
  • Loading branch information
c0bra committed May 6, 2013
1 parent ab0f207 commit e4b08a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/classes/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
var templates = ['rowTemplate', 'aggregateTemplate', 'headerRowTemplate', 'checkboxCellTemplate', 'checkboxHeaderTemplate', 'menuTemplate', 'footerTemplate'];

var promises = [];
templates.forEach(function(template) {
angular.forEach(templates, function(template) {
promises.push( self.getTemplate(template) );
});

Expand Down
20 changes: 20 additions & 0 deletions test/unit/directivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,26 @@ describe('directives', function () {
});
});
describe('grid', function () {
describe('initTemplates', function() {
it('should not call Array.forEach() on the template list (IE8 does not support)', inject(function ($rootScope, $compile) {
var elm = angular.element(
'<div ng-grid="gridOptions" style="width: 1000px; height: 1000px"></div>'
);
$compile(elm)($rootScope);

spyOn(angular, 'forEach');
spyOn(Array.prototype, 'forEach');

// Manually call the initTemplates() function again
elm.scope().gridOptions.ngGrid.initTemplates();

// dump(Array.prototype.forEach.mostRecentCall);

expect(angular.forEach).toHaveBeenCalled();
expect(Array.prototype.forEach).not.toHaveBeenCalled();
}));
});

describe('sortActual', function(){
it('should maintain row selection post-sort', function(){
scope.gridOptions.selectItem(0, true);
Expand Down

0 comments on commit e4b08a7

Please sign in to comment.