In my view form.html, I have the following code:
Size <select ng-model="size" ng-options...>[1..20]</select>
Limiter <select ng-model="limiter">[1..20]</select>
Then, in the controller form.js, I added:
$scope.$watch("limiter", function(newVal, oldVal) {
if (newVal !== oldVal) {
size=Math.min(limiter,size);
}
});
Everything was working well, but now I want to implement sizeMemory feature. The goal is to keep track of the original size so that if the limiter decreases the size, but it is then increased again, the size will return to its original value.
I attempted the following approach, but encountered an issue where the sizeMemory was also being modified whenever the limiter changed the size. I need to modify the size watch function to only trigger when the user manually sets a new value for size:
sizeMemory = size;
$scope.$watch("size", function(newVal, oldVal) {
if (newVal !== oldVal) {
sizeMemory=size;
}
});
$scope.$watch("limiter", function(newVal, oldVal) {
if (newVal !== oldVal) {
wantedSize = Math.max(size,sizeMemory);
size=Math.min(limiter,wantedSize);
}
});