0

I have tried several different methods or wrapping a simple jquery-ui slider, the first of which is:

//Slider control
TDApp.directive("tdControlSlider", ["TDSV", function (TDSV) {
     return {
           scope: {
                property: "=",
                min: "=",
                max: "=",
                step: "="
           },
           restrict: "E",
           replace: true,
           templateUrl: TDSV.TEMPLATE_PATH + "Controls/Slider.htm",
           link: function (scope, elem, attrs) {
                scope.sliderElem = elem.find(".sliderDiv").first();
                scope.sliderElem.slider({
                     min: scope.min,
                     max: scope.max,
                     step: scope.step,
                     slide: function (event, obj) {
                           scope.property = obj.value;
                           scope.$apply()
                           console.log(obj.value);
                           console.log(scope.property);                         
                     }
                });
           }
     };
}]);

I assumed this didn't work because of shadowing, so I opted instead to pass a reference to an object and the string value of one of its properties:

//Slider control
TDApp.directive("tdControlSlider", ["TDSV", function (TDSV) {
     return {
           scope: {
                object: "=",
                property: "@",
                min: "=",
                max: "=",
                step: "="
           },
           restrict: "E",
           replace: true,
           templateUrl: TDSV.TEMPLATE_PATH + "Controls/Slider.htm",
           link: function (scope, elem, attrs) {
                scope.sliderElem = elem.find(".sliderDiv").first();
                scope.sliderElem.slider({
                     min: scope.min,
                     max: scope.max,
                     step: scope.step,
                     slide: function (event, obj) {
                           scope.object[scope.property] = obj.value;
                           scope.$apply()
                           console.log(obj.value);
                           console.log(scope.object[scope.property]);
                     }
                });
           }
     };
}]);

In both cases, the console displays the expected values, but the model is not updated. Usually this has meant that the values are being shadowed across scopes, which is why I changed it to the second version, but that doesn't work either. Any ideas?

AaronF
  • 2,841
  • 3
  • 22
  • 32

0 Answers0