我有一个内部使用 ionRangeSlider 的滑块指令。单击按钮时,混合值和最大值已更改,但指令中未更新。我在链接中添加了监视功能。
下面是滑块指令
var app = angular.module('ionSlider',[]);
app.directive('ionslider',function($timeout){
return{
restrict:'AE',
require: 'ngModel',
scope:{
options:'='
},
template:'<div id="{{id}}" ></div>',
replace:true,
link:function($scope, $element, attrs, ngModel) {
// //function init(){
var init =function(){
$element.ionRangeSlider({
min: $scope.options.min,
max: $scope.options.max,
type: $scope.options.type,
prefix: $scope.options.prefix,
maxPostfix: $scope.options.maxPostfix,
prettify: $scope.options.prettify,
hasGrid: $scope.options.hasGrid,
gridMargin: $scope.options.gridMargin,
postfix:$scope.options.postfix,
from:$scope.options.from,
step:$scope.options.step,
hideMinMax:$scope.options.hideMinMax,
hideFromTo:$scope.options.hideFromTo,
onChange:$scope.options.onChange
});
};
init();
//OnChange
var update = function()
{
$element.ionRangeSlider ({
min: $scope.options.min,
max: $scope.options.max,
type: $scope.options.type,
prefix: $scope.options.prefix,
maxPostfix: $scope.options.maxPostfix,
prettify: $scope.options.prettify,
hasGrid: $scope.options.hasGrid,
gridMargin: $scope.options.gridMargin,
postfix:$scope.options.postfix,
from:$scope.options.from,
step:$scope.options.step,
hideMinMax:$scope.options.hideMinMax,
hideFromTo:$scope.options.hideFromTo,
onChange:$scope.options.onChange
});
};
//watch
$scope.$watch('options', function(value) {
$timeout(function(){ update(); });
});
}
}
});
相同的 HTML 代码如下:
<td style="width:30%;" class="normal_row"><span><input ng-model="ldcInput.value" type="text" id={{key}} ionslider options="{'min':ldcInput.minValue,'max':ldcInput.maxValue,'step':ldcInput.step}" ng-change="mathCalculation(ldcInput)"/></span></td>
上面的 min 和 max 滑块值会根据单击按钮而更改。但它没有反映在滑块中。请让我知道我在指令中哪里出错了。