有人可以提供范围的$ destroy事件的例子吗?以下是http://docs.angularjs.org/api/ng.$rootScope.Scope#$destroy的参考文档.
$摧毁()
从父作用域中删除当前作用域(及其所有子作用域).删除意味着对$ digest()的调用将不再传播到当前范围及其子节点.删除还意味着当前范围符合垃圾收集的条件.
$ destroy()通常由诸如ngRepeat之类的指令用于管理循环的展开.
在范围被销毁之前,在此范围内广播$ destroy事件.应用程序代码可以注册$ destroy事件处理程序,使其有机会执行任何必要的清理.
Sun*_*hah 106
演示: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);
});
};
});
Run Code Online (Sandbox Code Playgroud)
nia*_*her 19
$destroy 可以参考两件事:方法和事件
.directive("colorTag", function(){
return {
restrict: "A",
scope: {
value: "=colorTag"
},
link: function (scope, element, attrs) {
var colors = new App.Colors();
element.css("background-color", stringToColor(scope.value));
element.css("color", contrastColor(scope.value));
// Destroy scope, because it's no longer needed.
scope.$destroy();
}
};
})
Run Code Online (Sandbox Code Playgroud)
请参阅@ SunnyShah的回答.
| 归档时间: |
|
| 查看次数: |
110250 次 |
| 最近记录: |