2

Here I have to bind the ticks, value, maximum and minimum values dynamically by using angular-bootstrap-slider. But I am unable to bind the values.

CONTROLLER:

var app = angular.module("sliderApp", ['ui.bootstrap-slider']);

app.controller('sliderCtrl', function ($scope, $http) {
    var labels =[{ "val": 1, "txt": "one" }, { "val": 2, "txt": "2" }, { "val": 3, "txt": "3" }, { "val": 4, "txt": "4" }, { "val": 5, "txt": "5+" }];
    var ticks = [12, 24, 36, 48, 60, 72];
    /* maximum value functionality*/
    function getMax(labels, prop) {
        var max;
        for (var i = 0 ; i < labels.length ; i++) {
            if (!max || parseInt(labels[i][prop]) > parseInt(max[prop]))
                max = labels[i];
        }
        return max;
    }
    $scope.sliderMaxVal = getMax(labels, "val").val;
    console.log($scope.sliderMaxVal);

    /* Minimum value functionality*/
    function getMin(labels, prop) {
        var min;
        for (var i = 0 ; i < labels.length ; i++) {
            if (!min || parseInt(labels[i][prop]) < parseInt(min[prop]))
                min = labels[i];
        }
        return min;
    }
    $scope.sliderMinVal = getMin(labels, "val").val;

    $scope.vfg = 1200;

    this.sliderValue = 53;
    this.sliderLabels = function () {
        return labels;
    }
    this.sliderTicks = function () {
        return ticks;
    }
    this.myFormatter = function (value) {
        console.log('value %s', value);
        return '<span class="tooltip-header-title">' + value + ' months </span><br> ' + (value - 1) + ' payments + VFG <span class="glyphicon glyphicon glyphicon-tags" aria-hidden="true"></span>';
    }
});

HTML:

  <div class="col-md-4 .col-xs-4">
            <div ng-controller="sliderCtrl as slider">
                <slider ng-model="slider.sliderValue" min="{{sliderMinValue}}" step="1" max="72" value="sliderApp.sliderValue" ticks="slider.sliderTicks()" ticks-labels="slider.sliderLabels()" formatter="slider.myFormatter" tooltip="always"></slider>
                <p>Value: {{slider.sliderValue}}</p>
                <p>VFG: {{vfg}}</p>
            </div>
        </div>

Now, I have to bind the slider min and max value like {{sliderMinValue}} and {{sliderMaxValue}} instead of static values. But when I do this, I am getting this type of error as shown in below figure:

enter image description here

Plunker: https://plnkr.co/edit/mSuWAtL89DEDE88pwAm5?p=preview

halfer
  • 19,824
  • 17
  • 99
  • 186
anub
  • 527
  • 1
  • 4
  • 21

1 Answers1

1

Try to change it in order to use ng-min and ng-max:

<slider ng-model="slider.sliderValue" 
        ng-min="slider.sliderMinVal" 
        ng-max="slider.sliderMaxVal" 
        step="1" 
        value="sliderApp.sliderValue" 
        ticks="slider.sliderTicks()" 
        ticks-labels="slider.sliderLabels()"  
        formatter="slider.myFormatter" tooltip="always">
</slider>

Fork of your Plunker

Mistalis
  • 17,793
  • 13
  • 73
  • 97
  • but,the values are not getting inside of tooltip,it is showing as func,can you please check the plunker link once. – anub Apr 28 '17 at 06:57
  • @bpbsr I've forked your plunker [here](https://plnkr.co/edit/ihA1PVlQJHsz9NOCZu43?p=preview). – Mistalis Apr 28 '17 at 07:02