diff --git a/src/components/slider/slider.js b/src/components/slider/slider.js index 9355f7c0425..ae420806e79 100644 --- a/src/components/slider/slider.js +++ b/src/components/slider/slider.js @@ -45,7 +45,7 @@ * @param {number=} min The minimum value the user is allowed to pick. Default 0. * @param {number=} max The maximum value the user is allowed to pick. Default 100. */ -function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse) { +function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse, $log) { return { scope: {}, require: '?ngModel', @@ -185,22 +185,29 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi function redrawTicks() { if (!angular.isDefined(attr.mdDiscrete)) return; - var numSteps = Math.floor( (max - min) / step ); - if (!tickCanvas) { - var trackTicksStyle = $window.getComputedStyle(tickContainer[0]); - tickCanvas = angular.element(''); - tickCtx = tickCanvas[0].getContext('2d'); - tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black'; - tickContainer.append(tickCanvas); - } - var dimensions = getSliderDimensions(); - tickCanvas[0].width = dimensions.width; - tickCanvas[0].height = dimensions.height; - - var distance; - for (var i = 0; i <= numSteps; i++) { - distance = Math.floor(dimensions.width * (i / numSteps)); - tickCtx.fillRect(distance - 1, 0, 2, dimensions.height); + if (step > 0) { + + var numSteps = Math.floor( (max - min) / step ); + if (!tickCanvas) { + tickCanvas = angular.element(''); + tickContainer.append(tickCanvas); + + var trackTicksStyle = $window.getComputedStyle(tickContainer[0]); + tickCtx = tickCanvas[0].getContext('2d'); + tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black'; + } + var dimensions = getSliderDimensions(); + tickCanvas[0].width = dimensions.width; + tickCanvas[0].height = dimensions.height; + + var distance; + for (var i = 0; i <= numSteps; i++) { + distance = Math.floor(dimensions.width * (i / numSteps)); + tickCtx.fillRect(distance - 1, 0, 2, dimensions.height); + } + + } else { + $log.error('Slider step value must be greater than zero when in discrete mode'); } }