重置或重新初始化angularJS变量

时间:2016-04-01 12:03:18

标签: angularjs

我有Jquery UI滑块

<div  class="col-md-11 text-center time-range-wrapper">
    <!-- Time Slider Start --> 
    <div id="time-range">    
        <!--slider wrapper-->
        <div class="form_wrapper">                
            <div range-slider min="timeSlider.range.min" max="timeSlider.range.max" model-min="timeSlider.minTime" model-max="timeSlider.maxTime" filter="custom_time" step={{timeSlider.step}} show-values="true" attach-handle-values="true"></div>        
            <div class="time-slider-labels" ng-bind-html="timeSliderLabels()"></div>                
        </div>
    </div>
    <!-- Time Slider End --> 
</div>

Angular JS代码

// time slider values
        $scope.timeSlider = {
            range: {
                min: slider_min_val,
                max: slider_max_val,
            },
            minTime: min_slider_hours_in_minute,
            maxTime: max_slider_hours_in_minute,
            step: 15,
        };
        // end time slider values

如何在调用其他函数时初始化或重置所有值,让我们说函数是

$scope.getTestMethod = function() {

 // Here I wan to re initialize slider 

}

有任何办法......

1 个答案:

答案 0 :(得分:0)

非常简单,只需重置函数内的timeSlider变量即可。

$scope.getTestMethod = function() {

   $scope.timeSlider = {
        range: {
            min: 0,
            max: 9,
        },
        minTime: 0,
        maxTime: 9,
        step: 1,
    };

}

或者您甚至可以将值传递给函数:

$scope.getTestMethod = function(min, max, minTime, maxTime, step) {

   $scope.timeSlider = {
        range: {
            min: min,
            max: max,
        },
        minTime: minTime,
        maxTime: maxTime,
        step: step,
    };

}