javascript - Angular JS Directive Unloading Event or Equivalent - Stack Overflow

So, I have these widgets:<widget ng-repeat="widget in widgets"><widget>As you ca

So, I have these widgets:

<widget ng-repeat="widget in widgets"></widget>

As you can tell, they are created and removed by the ng-repeat.

So when someone does remove a widget, is there any where in the directive I can catch the event happening OR equivalent?

.directive('widget', function widget() {
    var directive = { 
        restrict: 'E',
        pile: pile
    };

    return directive;

    function pile() {
        return {
            pre: preLink,
            post: postLink
        };
    }

    function preLink(scope, element) {

    }

    function postLink(scope, element) {

    }
});

So, I have these widgets:

<widget ng-repeat="widget in widgets"></widget>

As you can tell, they are created and removed by the ng-repeat.

So when someone does remove a widget, is there any where in the directive I can catch the event happening OR equivalent?

.directive('widget', function widget() {
    var directive = { 
        restrict: 'E',
        pile: pile
    };

    return directive;

    function pile() {
        return {
            pre: preLink,
            post: postLink
        };
    }

    function preLink(scope, element) {

    }

    function postLink(scope, element) {

    }
});
Share Improve this question asked Jan 19, 2015 at 11:40 Callum LiningtonCallum Linington 14.4k14 gold badges80 silver badges156 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You can listen to the $destroy event which will be fired immediately prior to scope destruction.

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

scope.$on('$destroy', function () {
    console.log('captured $destroy event');
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962521a4603475.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信