gpt4 book ai didi

angularjs - 有人可以提供 AngularJS 中范围的 $destroy 事件的示例吗?

转载 作者:行者123 更新时间:2023-12-02 21:57:59 25 4
gpt4 key购买 nike

有人可以提供作用域 $destroy 事件的示例吗?这是来自http://docs.angularjs.org/api/ng.$rootScope.Scope#$destroy的引用文档

$destroy()

Removes the current scope (and all of its children) from the parent scope. Removal implies that calls to $digest() will no longer propagate to the current scope and its children. Removal also implies that the current scope is eligible for garbage collection.

The $destroy() is usually used by directives such as ngRepeat for managing the unrolling of the loop.

Just before a scope is destroyed a $destroy event is broadcasted on this scope. Application code can register a $destroy event handler that will give it chance to perform any necessary cleanup.

最佳答案

演示:http://jsfiddle.net/sunnycpp/u4vjR/2/

这里我创建了handle-destroy指令。

ctrl.directive('handleDestroy', function() {
return function(scope, tElement, attributes) {
scope.$on('$destroy', function() {
alert("In destroy of:" + scope.todo.text);
});
};
});

关于angularjs - 有人可以提供 AngularJS 中范围的 $destroy 事件的示例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14416894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com