以角度方式从列表中删除项目后显示通知

时间:2015-08-26 03:23:43

标签: javascript angularjs angularjs-ng-repeat

我有一个带删除按钮的项目列表。单击“删除”按钮时,将其从列表中删除。

Initial list

但点击删除按钮后,我想用“删除完成”消息替换已删除的项目。

After removing item from the list

这可能吗?

2 个答案:

答案 0 :(得分:1)

是的,有可能。假设数据以ng-repeat与表达式绑定,

tblShipments

因此,您需要在json数据中再添加一个属性。

答案 1 :(得分:1)

检查此样本...... 它会在3秒后删除删除红旗......

http://jsfiddle.net/leojavier/U3pVM/18175/

<div class="field" ng-app="App">
    <table ng-controller="Controller">
        <tr ng-repeat="item in table">
            <td ng-class="item.style" ng-class="item.style">{{item.name}}</td>
            <td><a href="javascript:void(0)" ng-click="delete(item, $index)">Delete</a></td> 
        </tr>
    </table>
</div>

JS

var App = angular.module('App', []);
App.controller('Controller', function($scope, $timeout){
    $scope.table = [
        {name : 'Dan', deleted:false},
        {name : 'Orlando'},
        {name : 'Dany'}
   ];

    $scope.delete = function(item, index){
        item.deleted = true;
        item.style = 'deleted';

        function destroy() {
        $scope.table.splice(index, 1)
        }

        $timeout(function(){destroy();}, 3000);
    }
});

CSS

body{
    font-family:arial;
}
a{
    text-decoration:none;
    color:red;
}

table{
width:300px;
}

td{
    border:thin solid #CCC;
    padding:10px;

}

tr{
 position:relative   
     width:300px;
}

.deleted:after{
    content:'DELETED';
    position:absolute;
    top:0;
    left:0;
    background:red;
    width:300px;
    color:#FFF;
    text-align:center;
    line-height:40px;
}

http://jsfiddle.net/leojavier/U3pVM/18175/