如何使用特定超时从 ng-repeat 中删除每个元素

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);

我需要的是。
如果我将一个元素添加到该数组,则只需在指定的超时后删除该元素。不是最后添加的元素。所以每个元素都会有自己的超时

这里有一个 plunker 需要帮助。 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);
};

Here 是一个工作的 plunker