我有一个动态ng-repeat
,用户可以在其中更改项目数。
简化的 JS:
$scope.items = [1, 2, 3, 4];
$scope.getBoxBackgroundColor = function () { return '#FF0000'; }
$scope.addItem = function () { $scope.items.push($scope.items.length + 1); }
HTML:
<div ng-repeat="item in items" ng-style="{ 'backgroundColor': getBoxBackgroundColor() }"></div>
<button ng-click="addItem()">Add Item</button>
问题:
添加新项目时,该ng-style
指令不会调用函数。getBoxBackgroundColor
有什么建议吗?
谢谢!