被稱爲兩次這樣的設置:功能在每次迭代
HTML
<li ng-repeat="item in data.checkList">
<i ng-class="faClass(item.status)"> </i> <span>{{item.Name}}</span>
</li>
JS
$scope.data.checkList = [
{'status':'COMPLETED', 'name':'Task 1'},
{'status':'NOT STARTED', 'name':'Task 2'}
];
$scope.faClass = function(status){
console.log(status);
};
瀏覽器控制檯
COMPLETED
NOT STARTED
COMPLETED
NOT STARTED
這是行爲嗎?我如何解決它並避免重複?
我那麼如何確保函數運行,只有兩次? – asprin
什麼是需要調用函數內ng-repeat – Sajeetharan
根據狀態,一些css類將應用於它 – asprin