I've got an angular app like:
angular.module('ngStyleApp', [])
.controller('testCtrl', function($scope) {
$scope.list = [1,2,3];
$scope.getStyles = function(index) {
console.log('getting styles for index ' + index);
return {
color: 'red'
};
};
});
with the corresponding markup:
<div ng-app="ngStyleApp">
<ul ng-controller="testCtrl">
<li ng-repeat="value in list" ng-style="getStyles($index)">
{{value}}
</li>
</ul>
</div>
The visible output is three red list items, as expected. But the statement is logged to the console a total of 6 times, implying that the view is rendered twice:
getting styles for index 0
getting styles for index 1
getting styles for index 2
getting styles for index 0
getting styles for index 1
getting styles for index 2
Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…