Ng-Options Expression Repeatedly Called

三世轮回 提交于 2019-12-02 02:16:20

The getOtherOrderDates will be called in each digest cycle so that angular knows whether to update options 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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!