My question is related to a directive that I have refactored:
HTML
<!-- Before -->
<slider value="sliderValue" floor="0" ceil="maxPrice"></slider>
<!-- New version -->
<slider value="sliderValue" options="sliderOptions"></slider>
<!-- Both directives use '=' bindings... -->
JS
$scope.sliderValue=0;
$scope.maxPrice = 1000;
$scope.sliderOptions = {
floor: 0,
ceil: $scope.maxPrice
};
//later
$scope.maxPrice = 2000;
With the old version, I could update $scope.maxPrice
, and it would automatically update the scope value of ceil
in the directive. I would like to achieve the same with the new version.
The first idea to come to my mind is using a $watch
on $scope.maxPrice
, but I have read many people explaining that using $watch
is a bad practice.
Then, I could update $scope.sliderOptions.ceil
manually every time I update $scope.maxPrice
but this is quite annoying.
N.B. $scope.maxPrice
is a business-logic value used in several places of the application while $scope.sliderOptions
is only used for the slider directive.