@@ -27,7 +27,7 @@ angular.module('ui.bootstrap-slider', [])
2727 link : function ( $scope , element , attrs , ngModelCtrl , $compile ) {
2828 var ngModelDeregisterFn , ngDisabledDeregisterFn ;
2929
30- initSlider ( ) ;
30+ var slider = initSlider ( ) ;
3131
3232 function initSlider ( ) {
3333 var options = { } ;
@@ -107,7 +107,11 @@ angular.module('ui.bootstrap-slider', [])
107107 setFloatOption ( 'value' , $scope . value , 5 ) ;
108108 }
109109
110- if ( $scope . formatter ) options . formatter = $scope . $eval ( $scope . formatter ) ;
110+ if ( attrs . formatter ) {
111+ options . formatter = function ( value ) {
112+ return $scope . formatter ( { value : value } ) ;
113+ }
114+ }
111115
112116
113117 // check if slider jQuery plugin exists
@@ -140,19 +144,18 @@ angular.module('ui.bootstrap-slider', [])
140144 }
141145 angular . forEach ( updateEvent , function ( sliderEvent ) {
142146 slider . on ( sliderEvent , function ( ev ) {
143- ngModelCtrl . $setViewValue ( ev ) ;
144147 $timeout ( function ( ) {
145- $scope . $apply ( ) ;
148+ ngModelCtrl . $setViewValue ( ev ) ;
146149 } ) ;
147150 } ) ;
148151 } ) ;
149152 slider . on ( 'change' , function ( ev ) {
150- ngModelCtrl . $setViewValue ( ev . newValue ) ;
151153 $timeout ( function ( ) {
152- $scope . $apply ( ) ;
154+ ngModelCtrl . $setViewValue ( ev . newValue ) ;
153155 } ) ;
154156 } ) ;
155157
158+
156159 // Event listeners
157160 var sliderEvents = {
158161 slideStart : 'onStartSlide' ,
@@ -164,15 +167,9 @@ angular.module('ui.bootstrap-slider', [])
164167 slider . on ( sliderEvent , function ( ev ) {
165168 if ( $scope [ sliderEventAttr ] ) {
166169
167- var callback = function ( ) {
170+ $timeout ( function ( ) {
168171 fn ( $scope . $parent , { $event : ev , value : ev } ) ;
169- }
170-
171- if ( $rootScope . $$phase ) {
172- $scope . $evalAsync ( callback ) ;
173- } else {
174- $scope . $apply ( callback ) ;
175- }
172+ } ) ;
176173 }
177174 } ) ;
178175 } ) ;
@@ -195,21 +192,30 @@ angular.module('ui.bootstrap-slider', [])
195192 // deregister ngModel watcher to prevent memory leaks
196193 if ( angular . isFunction ( ngModelDeregisterFn ) ) ngModelDeregisterFn ( ) ;
197194 ngModelDeregisterFn = $scope . $watch ( 'ngModel' , function ( value ) {
198- if ( $scope . range ) {
199- slider . setValue ( value ) ;
200- } else {
201- slider . setValue ( parseFloat ( value ) ) ;
202- }
195+ $timeout ( function ( ) {
196+ if ( $scope . range ) {
197+ slider . setValue ( value ) ;
198+ } else {
199+ slider . setValue ( parseFloat ( value ) ) ;
200+ }
201+ slider . relayout ( ) ;
202+ } ) ;
203203 } , true ) ;
204+
205+ return slider ;
204206 }
205207
206208
207209 var watchers = [ 'min' , 'max' , 'step' , 'range' , 'scale' ] ;
208210 angular . forEach ( watchers , function ( prop ) {
209211 $scope . $watch ( prop , function ( ) {
210- initSlider ( ) ;
212+ slider = initSlider ( ) ;
211213 } ) ;
212214 } ) ;
215+
216+ $scope . $on ( 'slider:relayout' , function ( ) {
217+ slider . relayout ( ) ;
218+ } ) ;
213219 }
214220 } ;
215221 } ] )
0 commit comments