I'm making the jquery-ui slider into a directive and got it working when you slide the slider, it updates the model.
However, I'm trying to make it so when you also have an input box and input the value, it updates the ui slider itself.
I got this from a previous stack-overflow thread with my similar issue
<div ng-app="myApp">
<div ng-controller="SomeController">
Price: {{price}}
<div slider config="sliderConfig" model="price" class="cdbl-slider"></div>
<input type="input" ng-model="price">
</div>
</div>
js
var myApp = angular.module("myApp", []);
myApp.controller("SomeController", function($scope) {
$scope.sliderConfig = {
min: 50,
max: 500,
step: 1
}
$scope.price = 50;
$scope.setPrice = function(price) {
$scope.price = price;
}
});
myApp.directive("slider", function() {
return {
restrict: 'A',
scope: {
config: "=config",
price: "=model"
},
link: function(scope, elem, attrs) {
var setModel = function(value) {
scope.model = value;
}
$(elem).slider({
range: false,
min: scope.config.min,
max: scope.config.max,
step: scope.config.step,
slide: function(event, ui) {
scope.$apply(function() {
scope.price = ui.value;
});
}
});
}
}
});
You can see when you update the input value - the slider doesn't go to the typed value. So, I tried adding change method to the slider with the same properties as slide with the $apply setting the ui.value to scope.value but that didn't work. I also tried a $watch function that updated the ui-value whenever the ng-model changed but that also didn't work.
Any ideas?