這裏是一個ngRepeat,它爲用戶重複Alerts。我想在一個時間段內逐一顯示每個警報。我正在使用ngShow和一個計數器變量$ scope.showedItem。
模板:
<div class="container" >
<div ng-repeat="headerNotification in headerNotification.list" ng-show="{{showedItem==$index}}">
<h3>{{headerNotification.getText()}}</h3>
<button ng-click="headerNotification.do()" class="btn btn-warning">{{headerNotification.getButtonText()}}</button>
</div>
</div>
控制器:
componentHeaderModule.controller('headerController', [
'$rootScope',
'$scope',
'componentHeaderNotification',
'$interval',
function ($rootScope, $scope, componentHeaderNotification, $interval)
{
...
$scope.showedItem = 1;
$interval(function(){
$scope.showedItem++;
if ($scope.showedItem > $scope.headerNotification.list.length)
$scope.showedItem = 0;
}, 5000);
}]);
當我在看DeveloperTool,我看到NG秀值改變每5秒,然而,查看不爽,同樣的警報一直在顯示。甚至,物品類沒有改變。
可能是什麼問題?我對雙向綁定的理解是一個很大的錯誤?
我不相信這一點!儘管ngShow值正在改變,它根本不會影響!我需要更加努力地學習它! – efirat
一個關鍵是角度不會把屬性放在手錶上。那麼,什麼情況是,在鏈接時傳遞的屬性是什麼評價。現在你正在傳遞要麼TRUE;或'FALSE'。即使html正在改變,它也不會被重新評估。這就是爲什麼你要在鏈接傳遞表達。 – KayakDave