如何在angular-bootstrap-model中动态绑定值?

时间:2017-04-28 06:44:38

标签: javascript angularjs bootstrap-slider

这里我必须使用angular-bootstrap-slider动态绑定ticks,value,maximum和minimum值。但是我无法绑定这些值。

控制器:

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>

现在,我必须将滑块最小值和最大值绑定为{{sliderMinValue}}和{{sliderMaxValue}}而不是静态值。但是当我这样做时,我会遇到这种类型的错误,如下图所示:

enter image description here

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

1 个答案:

答案 0 :(得分:0)

尝试更改它以使用ng-min and ng-max

var clientContext = new SP.ClientContext();
var groupId = ...;  // my group Id
var group = clientContext.get_web().get_siteGroups().getById(groupId);
clientContext.load(group,"CanCurrentUserViewMembership");
clientContext.load(group,"CanCurrentUserManageGroup");
clientContext.executeQueryAsync(
function(sender,args){
    if(group.get_canCurrentUserViewMembership() == true)
        {
            if(group.get_canCurrentUserManageGroup() == false) // this check for group owners 
            {     //access denied logic
            }           
        }     
    },
    function(sender,args){   //failed   });

Fork of your Plunker