加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:58:21 所属栏目:安全 来源:网络整理
导读:提供示例的$ 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
提供示例的$ 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);
        });
    };
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读