What I want when you click on the slider, then on its tooltip it show text in place of the number.
Here is the code:
HTML:
<div ng-controller="AppCtrl" class="sliderdemoBasicUsage" ng-app="MyApp">
<br>
<br>
<br>
<br>
<md-content style="margin: 16px; padding:16px">
<br>
<br>
<md-slider flex class="md-primary" md-discrete ng-model="rating3" step="1" min="1" max="5" aria-label="rating">
</md-slider>
</md-content>
</div>
Angular Code:
angular.module('MyApp')
.controller('AppCtrl', function($scope) {
});
Or you can refer the following link https://codepen.io/ankur-tiwari/pen/bVNEKJ
Angular Material does not support it.
for more detail check slider.js of angular-material module
function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse, $log) {
return {
scope: {},
require: '?ngModel',
template:
'<div class="md-slider-wrapper">\
<div class="md-track-container">\
<div class="md-track"></div>\
<div class="md-track md-track-fill"></div>\
<div class="md-track-ticks"></div>\
</div>\
<div class="md-thumb-container">\
<div class="md-thumb"></div>\
<div class="md-focus-thumb"></div>\
<div class="md-focus-ring"></div>\
<div class="md-sign">\
<span class="md-thumb-text"></span>\
</div>\
<div class="md-disabled-thumb"></div>\
</div>\
</div>',
compile: compile
};
inside this code
<span class="md-thumb-text"></span>
is used to render the slider's range number. and following method is used to render it
function postLink(scope, element, attr, ngModelCtrl){
}
you can modify function's content like this
var _values = ["very low", "low", "average", "good", "best"];
thumbText.text( _values[ngModelCtrl.$viewValue] );
to render text rather integer value.
<p ng-bind="val" ng-init="val=20"></p>
<div class="slider" ui-jq="slider" ng-slider-model="val" ui-options="sliderOpt4"></div>
</div>
Here is the an directive you can access and show the value of controller value ..with html and css
.directive('ngSliderModel', ['$parse', function($parse) {
return {
scope: {
ngSliderModel: '=',
uiOptions: '='
},
restrict: 'A',
required: ['ngSliderModel'],
link: function(scope, element, attrs) {
// check there is uiOption or not
var options = ('uiOptions' in attrs) ? scope.uiOptions : {};
// get the value of ngSlider Model
var val = scope.ngSliderModel;
// if value is range [15,25] then return values for uiOptions propertyName else value for singles
var propName = (angular.isArray(val)) ? 'values' : 'value';
/* if you want to slide when the scope value changed not from slider...
watch the ngSliderModel attribute
*/
scope.$watch('ngSliderModel', function(newValue){
element.slider(propName, newValue);
});
// set value for options
options[propName] = val;
// binding slide event
element.bind('slide', function() {
// Read the current value
var value = element.slider('option', propName);
scope.$apply(function() {
// Apply the value to scope
scope.ngSliderModel = value;
});
});
}
};
}]);
Unfortunately that functionality is not supported as it's not technically part of the material spec for sliders.
For a likert scale you should consider the selection controls spec of material. Otherwise, you can get away with it in Angular Material by using a horizontal row of radio buttons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With