Using angular-bootstrap-slider based on bootstrap-slider. This extends a previous question regarding get value as string
I want to set the shown value when the page is loaded to be any other value than the first one.
Let's say I want 'blue' to be shown and not 'red'
How do I set a value that will be returned from another $scope.
Or perhaps how do I set the default value of the slider?
I have a working Plunker example and code below
script:
$scope.colors = [{'id': 0,'label': 'red'},{'id': 1,'label': 'blue'},{'id': 2,'label': 'green'}];
function getAttrs(collection, attr) {
var attrArray = [];
angular.forEach(collection, function(item) {
attrArray.push(item[attr]);
})
return attrArray;
}
$scope.colorTypeSlider = {
ticks: getAttrs($scope.colors, 'id'), // [0,1,3]
ticks_labels: getAttrs($scope.colors, 'label'), // ['red', 'blue','green']
ticks_snap_bounds: 50,
};
$scope.selectedColor = '';
$scope.selectColor = function ($event,value,collection) {
console.log('value is ' + value);
$scope.selectedColor = collection[value];
};
html:
<slider ng-model="colors"
ticks="colorTypeSlider.ticks"
ticks-labels="colorTypeSlider.ticks_labels"
ticks-snap-bounds="colorTypeSlider.ticks_snap_bounds"
on-start-slide="selectColor($event,value,colorTypeSlider.ticks_labels)"></slider>
<h6> value check is: {{selectedColor}} </h6>