Dynamically update ion.rangeSlider ngModel in AngularJS directive

后端 未结 2 1467
栀梦
栀梦 2020-12-19 23:55

I\'m trying to update the value of an Ion.RangeSlider when its bound ng-model scope variable changes. The model updates when the Ion.RangeSl

2条回答
  •  没有蜡笔的小新
    2020-12-20 00:16

    Just use slider.update() inside your directive and you will be fine:

    var app = angular.module('myApp', []);
    
    app.controller('MainCtrl', function ($scope, $rootScope, $timeout) {
    
        $scope.someNumber = 15;
        $scope.apply = false;
    
    }).directive('ionRangeSlider', function ionRangeSlider() {
       return {
          restrict: 'A',
          scope: {
             rangeOptions: '=',
             model: '=ngModel',
             apply: '=apply'
          },
          link: function (scope, elem, attrs) {
             elem.ionRangeSlider(scope.rangeOptions);
             scope.$watch('apply',function () {
              if (scope.apply) {
                scope.apply = false;
                var slider = elem.data("ionRangeSlider");            
                slider.update({
                   from: scope.model
                });
              }
             });
          }
       }
    });
    
    
    
    
    
    
    
    
    

    Text input updates slider and vice-versa.


提交回复
热议问题