Skip to content
This repository was archived by the owner on Apr 1, 2018. It is now read-only.

Commit f9613b3

Browse files
committed
Merge pull request seiyria#74 from santam85/master
Using scope properties for event handlers
2 parents 3b3b231 + acc93b3 commit f9613b3

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

slider.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('ui.bootstrap-slider', [])
2-
.directive('slider', ['$parse', '$timeout', function ($parse, $timeout) {
2+
.directive('slider', ['$parse', '$timeout', '$rootScope', function ($parse, $timeout, $rootScope) {
33
return {
44
restrict: 'AE',
55
replace: true,
@@ -110,8 +110,9 @@ angular.module('ui.bootstrap-slider', [])
110110
};
111111

112112
// destroy previous slider to reset all options
113-
slider.slider(options);
114-
slider.slider('destroy');
113+
if(slider.data("slider"))
114+
slider.slider('destroy');
115+
115116
slider.slider(options);
116117

117118
// everything that needs slider element
@@ -146,15 +147,13 @@ angular.module('ui.bootstrap-slider', [])
146147
slideStop: 'onStopSlide'
147148
};
148149
angular.forEach(sliderEvents, function (sliderEventAttr, sliderEvent) {
149-
slider.on(sliderEvent, function (ev) {
150-
151-
if (attrs[sliderEventAttr]) {
152-
var invoker = $parse(attrs[sliderEventAttr]);
153-
invoker($scope.$parent)(ev, ev.value);
154-
155-
$timeout(function () {
156-
$scope.$apply();
157-
});
150+
slider.on(sliderEvent, function () {
151+
if ($scope[sliderEventAttr]) {
152+
if ($rootScope.$$phase) {
153+
$scope.$evalAsync($scope[sliderEventAttr]);
154+
} else {
155+
$scope.$apply($scope[sliderEventAttr]);
156+
}
158157
}
159158
});
160159
});
@@ -175,12 +174,9 @@ angular.module('ui.bootstrap-slider', [])
175174
});
176175

177176
// deregister ngModel watcher to prevent memory leaks
178-
if (angular.isFunction(ngModelDeregisterFn)) {
179-
ngModelDeregisterFn();
180-
ngModelDeregisterFn = null;
181-
}
177+
if (angular.isFunction(ngModelDeregisterFn)) ngModelDeregisterFn();
182178
ngModelDeregisterFn = $scope.$watch('ngModel', function (value) {
183-
slider.slider('setValue', value);
179+
slider.slider('setValue', parseFloat(value));
184180
}, true);
185181
}
186182
}

0 commit comments

Comments
 (0)