AngularJS Ion.RangeSlider不更新min&最大动态更改特定按钮

时间:2015-01-21 10:42:56

标签: javascript jquery html angularjs rangeslider

我有一个滑块的指令,它是特意使用的  ionRangeSlider。在单击按钮上,混合和最大值将更改  但它没有在指令中更新。我添加了监视功能  链接。

下面是滑块指令

var app = angular.module('ionSlider',[]);
app.directive('ionslider',function($timeout){
return{
    restrict:'AE',
    require: 'ngModel',
    scope:{
    options:'='
    },
    template:'<div id="{{id}}" ></div>',
    replace:true,
    link:function($scope, $element, attrs, ngModel) {
       // //function init(){
        var init =function(){
            $element.ionRangeSlider({
                min: $scope.options.min,
                max: $scope.options.max,
                type: $scope.options.type,
                prefix: $scope.options.prefix,
                maxPostfix: $scope.options.maxPostfix,
                prettify: $scope.options.prettify,
                hasGrid: $scope.options.hasGrid,
                gridMargin: $scope.options.gridMargin,
                postfix:$scope.options.postfix,
                from:$scope.options.from,
                step:$scope.options.step,
                hideMinMax:$scope.options.hideMinMax,
                hideFromTo:$scope.options.hideFromTo,
                onChange:$scope.options.onChange
            });
        };
        init();
      //OnChange
     var    update = function()
        {
         $element.ionRangeSlider ({
              min: $scope.options.min,
                max: $scope.options.max,
                type: $scope.options.type,
                prefix: $scope.options.prefix,
                maxPostfix: $scope.options.maxPostfix,
                prettify: $scope.options.prettify,
                hasGrid: $scope.options.hasGrid,
                gridMargin: $scope.options.gridMargin,
                postfix:$scope.options.postfix,
                from:$scope.options.from,
                step:$scope.options.step,
                hideMinMax:$scope.options.hideMinMax,
                hideFromTo:$scope.options.hideFromTo,
                onChange:$scope.options.onChange
         });

        };
    //watch
      $scope.$watch('options', function(value) {
        $timeout(function(){ update(); }); 

      });
     }
    }
});

相同的HTML代码如下:

    <td  style="width:30%;" class="normal_row"><span><input ng-model="ldcInput.value" type="text" id={{key}} ionslider options="{'min':ldcInput.minValue,'max':ldcInput.maxValue,'step':ldcInput.step}" ng-change="mathCalculation(ldcInput)"/></span></td>

上面的min和max滑块值会根据按钮的变化而改变。但它没有反映在slide.Please让我知道我在指令中出错了。

1 个答案:

答案 0 :(得分:1)

由于iQuery注入了ion.RangeSlider,因此无法通过再次调用注入来更新其任何属性。

我通过向此fork添加可更新属性和一些缺少的属性改进了现有的指令,这将解决您的问题。有关如何使用它的示例,请参阅github页面。

/**
 * Created by Abdullah on 9/19/14.
 * 
 * Modified and enhanced by Juergen Wahlmann on 3/5/15
 */

var app = angular.module('ionSlider',['ngRoute']);


app.directive('ionslider',function($timeout){
return{
    restrict:'E',
    scope:{min:'=',
        max:'=',
        type:'@',
        prefix:'@',
        maxPostfix:'@',
        prettify:'@',
        hasGrid:'@',
        gridMargin:'@',
        postfix:'@',
        step:'@',
        hideMinMax:'@',
        hideFromTo:'@',
        from:'=',
        disable:'=',
        onChange:'=',
        onFinish:'='

    },
    template:'<div></div>',
    replace:true,
    link:function($scope,$element,attrs){
        (function init(){
            $($element).ionRangeSlider({
                min: $scope.min,
                max: $scope.max,
                type: $scope.type,
                prefix: $scope.prefix,
                maxPostfix: $scope.maxPostfix,
                prettify: $scope.prettify,
                hasGrid: $scope.hasGrid,
                gridMargin: $scope.gridMargin,
                postfix:$scope.postfix,
                step:$scope.step,
                hideMinMax:$scope.hideMinMax,
                hideFromTo:$scope.hideFromTo,
                from:$scope.from,
                disable:$scope.disable,
                onChange:$scope.onChange,
                onFinish:$scope.onFinish
            });
        })();
        $scope.$watch('min', function(value) {
            $timeout(function(){ $($element).data("ionRangeSlider").update({min: value}); });
        },true);
        $scope.$watch('max', function(value) {
            $timeout(function(){ $($element).data("ionRangeSlider").update({max: value}); });
        });
        $scope.$watch('from', function(value) {
            $timeout(function(){ $($element).data("ionRangeSlider").update({from: value}); });
        });
        $scope.$watch('disable', function(value) {
            $timeout(function(){ $($element).data("ionRangeSlider").update({disable: value}); });
        });
    }
}
});

ionRangeSlider-Angular-Directive