I am having multiple issues with my element in angular and am trying to understand what is going on. My first step is to understand why the multiple
To avoid triggering your loops in every digest loop you can use one time binding ::value
.
<select ng-options="theorderdate as theorderdate for theorderdate in ::getOtherOrderDates(Bread.text)"
ng-model="randomDateRomantic.randomDateRomantic"
ng-change="soRomantic(Bread.text)"></select>
Thanks to that expression inside ng-options
will be evaluated only once and the watcher will be removed after first evaluation which will stop your function being triggered in next digest loop iterations.
DOCS
The getOtherOrderDates
will be called in each digest cycle so that angular knows whether to update option
s in select
. That's most likely the reason you're seeing this method being called many times.
If you're worried about performance impact of this loop you can build the options upfront inside your controller
store it in $scope
like so:
$scope.options = $scope.getOtherOrderDates($scope.Bread.text);
whenever $scope.Bread.text
changes and then use $scope.options
inside your template.