Asdwq Qwksf Asdwq Qwksf - 20 days ago 6
AngularJS Question

Angular - how to check when select options are updated?

I have the following select element:

<select id="expiry" class="input col-sm-12 col-xs-12 ng-pristine ng-valid ng-touched" ng-model="selectedInstrumentExpiration" ng-options="item.expire | timezone: 'EST' | date:'MMM dd, yyyy HH:mm' for item in selectedInstrumentCode.value | filterExpired | orderBy: 'expire'" ng-change="changeInstrumentExpiration()">


It's being used to hold certain expiration times, generally between 5 minute intervals and once one of them is reached it's removed from the list and the next one comes on top.

What I'd like is to execute something when the new one comes on top. I tried with the function specified at ng-change (changeInstrumentExpiration()) but it only works when the user changes them manually. I also tried with watchCollection but that didn't work either.

What would you say is the best course of action in this case? I'm relatively new to Angular so some help would be greatly appreciated :)

Answer

You can use AngularJS watch function to detect for any change

  $scope.$watch('data', function (newVal, oldVal) { /*...*/ }, true);
Comments