angularjs – 提供范围的$destroy事件的示例?

前端之家收集整理的这篇文章主要介绍了angularjs – 提供范围的$destroy事件的示例?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
提供示例的$ 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);
        });
    };
});
原文链接:https://www.f2er.com/angularjs/146405.html

猜你在找的Angularjs相关文章