AngularJS watch DOM change

前端 未结 5 2059
生来不讨喜
生来不讨喜 2020-11-29 05:31

I have one auto-carousel directive which iterates through the linked element\'s children.

The children however are not yet loaded in th

5条回答
  •  孤街浪徒
    2020-11-29 06:13

    If you need to watch for any changes deeper in the element's dom, MutationObserver is the way to go :

    .directive('myDirective', function() {
        return {
            ...
            link: function(scope, element, attrs) {
                var observer = new MutationObserver(function(mutations) {
                    // your code here ...
                });
                observer.observe(element[0], {
                    childList: true,
                    subtree: true
                });
            }
        };
    });
    

提交回复
热议问题