移除元素时的 angularJS 通知 [英] angularJS notification when element is removed

查看:32
本文介绍了移除元素时的 angularJS 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新指令,我想知道如何在 angular 从 DOM 中删除元素时收到通知.
我的目标是在删除元素时添加 jquery 动画.

I am creating a new directive and I wondering how to be notified when angular remove the element from the DOM.
My aim is to add a jquery animation when an element is removed.

推荐答案

如果您尝试为元素的移除设置动画,则需要在移除元素之前执行此操作.

If you are trying to animate the removal of element you need to do this before it is removed.

我创建了一个 fiddle 来演示这一点.

I've created a fiddle demonstrating this.

在第一部分中,您将监听 $destroy 事件,该事件对从 DOM 中删除的元素进行角度调用.

In the first section you listen the $destroy event that angular call to elements that are being removed from DOM.

在第二种情况下,我创建了一个淡出并自动删除元素的指令.

In the second case I've created a directive that fadeOut and remove the element automatic.

在第三种情况下,指令只是淡出元素并将移除传递给控制器​​.

In the third case the directive just fadeOut the element and the removal is passed to controller.

如果你想淡出被移除的元素,那么你不能使用第一个选项.

If you want to fadeOut the element that are removed then you can't use the first option.

在第二个和第三个之间我个人推荐第三个,因为它更灵活.

Between the second and the third I personally suggest the third because it is more flexible.

这篇关于移除元素时的 angularJS 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆