可能的角度范围阴影无法解释

时间:2014-08-15 17:58:07

标签: javascript angularjs jquery-ui angularjs-scope shadowing

我尝试了几种不同的方法或包装一个简单的jquery-ui滑块,第一个是:

//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);                         
                     }
                });
           }
     };
}]);

我认为这不会因为阴影而起作用,所以我选择传递一个对象的引用和它的一个属性的字符串值:

//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]);
                     }
                });
           }
     };
}]);

在这两种情况下,控制台都会显示预期值,但不会更新模型。通常这意味着值会在范围内被遮蔽,这就是为什么我将其更改为第二个版本,但这也不起作用。有什么想法吗?

0 个答案:

没有答案