AngularJS watch DOM change

前端 未结 5 2047
生来不讨喜
生来不讨喜 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:29

    You could try to compile the directive contents first inside your link function. For example:

    angular.module('myApp').directive('autoCarousel', ['$compile', function ($compile) {
    
        return {
            templateUrl: 'views/auto-carousel.html',
            restrict: 'A',
            replace: true,
            link: function (scope, element, attr) {
                $compile(element.contents())(scope);
    
                // your code goes here
            }
        }
    }]);
    

提交回复
热议问题