我正在为jquery-knob小部件编写angular封装。只要最大值不变,以下内容就有效。如果更改了最大值,则ng-model绑定将丢失。如果我不在观察的开头销毁旋钮小部件,则最大值不会改变。
//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]);
也没有起作用。有什么建议吗?