我正在为jquery-knob小部件设计一个角度包装器。只要最大值不变,以下工作。如果是这样,则ng模型绑定将丢失。如果我没有在手表开头销毁旋钮小部件,则最大值不会改变。
//Directive
app.directive('knobWidget', function () {
return {
scope: {
maxbinding: "=maxbinding",
maxbindingprop: "@maxbindingprop"
},
restrict: 'A',
require: 'ngModel',
link: function (scope, elem, attrs, ngModel) {
ngModel.$render = function () {
$(elem).val(ngModel.$viewValue).trigger("change");
};
scope.$watch('maxbinding', function (newVal) {
$(elem).knob('destroy');
$(elem).knob({
min: 0,
max: scope.maxbinding[scope.maxbindingprop],
value: ngModel.$viewValue,
change: function (changeVal) {
scope.$apply(function () {
ngModel.$setViewValue(changeVal);
});
}
});
});
}
};
});
//Markup
<input knob-widget data-min="0" maxbinding="arr" maxbindingprop="length" ng-model="currentStop" />
这样做的:
$(elem).knob('max', scope.maxbinding[scope.maxbindingprop]);
也不起作用。有什么想法吗?
答案 0 :(得分:1)
使用trigger('configure')
后跟trigger('change')
应该可以解决问题
$(elem).trigger('configure', {
'max': scope.maxbinding[scope.maxbindingprop];
});
$(elem).trigger('change');