I have a use case where I need the slider-directive to update configuration & model value dynamically through a controller. For this I am trying to a create a two way data binding. However, I am not able to find the right way to create two way data-binding in directive. Following is the code. Currently an slide event on slider triggers directive to update 'scope.model'. Though it doesn't respond to controller updates for 'scope.config' or 'scope.model':
.directive("slider", function() {
return {
restrict: 'A',
scope: {
config: "=config",
model: "=model",
trigger: '=trigger'
},
link: function(scope, elem, attrs) {
//Data Binding to be done here using $watch for scope.model
$(elem).slider({
range: "min",
min: scope.config.min,
max: scope.config.max,
value: scope.model,
step: scope.config.step,
slide: function(event, ui) {
scope.$apply(function() {
scope.model = ui.value;
});
console.log(scope.model);
scope.$apply(scope.trigger);
}
});
}
}
});
Please help me in this. I have gone through all the available answers but wasn't able to find the suitable answer