非常简单的问题:在
这里是一个示例Plunker:
正如您所见,单击“DELETE”按钮会在
AngularJS 1.2.x
中,是否可以(以及如何)在从作用域中删除项目时触发ngAnimate
?这里是一个示例Plunker:
http://plnkr.co/edit/tpl:FrTqqTNoY8BEfHs9bB0f?p=preview
代码:
<body ng-controller="MainCtrl">
<div ng-repeat="img in imgs" class="my-repeat-animation">
<img ng-src="{{img}}" />
<button class="btn btn-primary" ng-click="remove(img)">DELETE</button>
</div>
</body>
脚本:
app.controller('MainCtrl', function($scope) {
$scope.imgs = ['http://cache.mrporter.com/images/products/362812/362812_mrp_in_l.jpg', 'http://cache.mrporter.com/images/products/362807/362807_mrp_in_l.jpg', 'http://cache.mrporter.com/images/products/364762/364762_mrp_in_l.jpg', 'http://cache.mrporter.com/images/products/357020/357020_mrp_in_l.jpg']
$scope.remove = function(image){
var index = $scope.imgs.indexOf(image);
$scope.imgs.splice(index,1);
}
});
正如您所见,单击“DELETE”按钮会在
$scope.imgs
上运行splice()
。我想对此进行动画处理,而不是让它简单地消失。我正在使用从this Year Of Moo article复制和粘贴的过渡效果,当过滤范围时它可以很好地工作,但显然在从范围中删除时无法工作。