[英]How to remove each element from ng-repeat with a specific timeout
如何從ng-repeat數組中刪除值(添加時超時)。
$timeout(function() {
$scope.datas.splice($scope.datas[$scope.datas.length - 1]) // just something
}, 4000);
我需要的是。
如果我將元素添加到該數組,則僅在指定的超時后必須刪除該元素。 不是最后添加的元素。 所以每個元素都有自己的超時時間
這是一些幫助的朋克。 https://plnkr.co/edit/5TtcwRqiXGeAOddn5wPF?p=preview 。
我不知道如何實現這一目標。 需要一點幫助。
謝謝。
您可以在addValue函數中使用超時。 在此超時內,您將獲得添加元素的索引,並按如下所示將其刪除:
$scope.addValue = function() {
var element = $scope.datas[$scope.datas.length - 1] + 1;
$scope.datas.push(element);
$timeout(function(){
var index = $scope.datas.indexOf(element);
$scope.datas.splice(index, 1)
}, 2000);
};
這是一個工作的家伙
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.