Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "ng-jsgrid", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "JSGrid for Angular", | ||
@@ -5,0 +5,0 @@ "main": "'src/ng-jsgrid.core.js'", |
@@ -5,3 +5,3 @@ (function() { | ||
angular.module('ngjsgrid', []) | ||
.directive('ngJsgrid', function() { | ||
.directive('ngJsgrid', ["$timeout", function($timeout) { | ||
return { | ||
@@ -15,2 +15,4 @@ restrict: 'A', | ||
link: function(scope, $element, attrs) { | ||
var linking = true; | ||
$element.jsGrid(scope.config); | ||
@@ -20,8 +22,16 @@ | ||
scope.$watch('config.' + key, function(value) { | ||
if(linking) | ||
return; | ||
$element.jsGrid('option', key, value); | ||
}); | ||
}); | ||
// NOTE: postpone turning off linking to avoid $watch calls right after initialization | ||
$timeout(function() { | ||
linking = false; | ||
}); | ||
} | ||
}; | ||
}); | ||
}]); | ||
})(); |
@@ -5,8 +5,10 @@ | ||
var $scope; | ||
var $timeout; | ||
beforeEach(module('ngjsgrid')); | ||
beforeEach(inject(function(_$compile_, _$rootScope_){ | ||
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_){ | ||
$compile = _$compile_; | ||
$scope = _$rootScope_; | ||
$timeout = _$timeout_; | ||
})); | ||
@@ -35,4 +37,7 @@ | ||
}; | ||
var element = $compile('<div ng-jsgrid="config"></div>')($scope); | ||
$scope.$digest(); | ||
$timeout.flush(); | ||
var newModelValue = []; | ||
@@ -48,18 +53,22 @@ | ||
it('should change model when grid option changed', function() { | ||
it('should prevent option changing on initialization', function() { | ||
// arrange | ||
var optionChangedCalled = 0; | ||
$scope.config = { | ||
data: [] | ||
data: [], | ||
onOptionChanged: function() { | ||
optionChangedCalled++; | ||
} | ||
}; | ||
var element = $compile('<div ng-jsgrid="config"></div>')($scope); | ||
$scope.$digest(); | ||
var newOptionValue = []; | ||
// act | ||
$(element).jsGrid('option', 'data', newOptionValue); | ||
var element = $compile('<div ng-jsgrid="{ data: config.data, onOptionChanged: config.onOptionChanged }"></div>')($scope); | ||
$scope.$digest(); | ||
$timeout.flush(); | ||
// assert | ||
expect($scope.config.data).toBe(newOptionValue); | ||
expect(optionChangedCalled).toBe(0); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1407060
32977