且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJS如何在替换之前访问指令中的元素

更新时间:2022-06-23 02:28:39

我相信您正在寻找 transclude 函数(链接到1.0.8文档).您可以看到发生了什么事:

I believe you're looking for the transclude function (link is to 1.0.8 docs). You can see what's going on with:

app.directive('xxx', function($log){
    return {
        restrict: 'A',
        transclude: true,
        compile: function(element, attrs, transclude) {

            $log.info("every instance element:", element);

            return function (scope, iElement, iAttrs) {

                $log.info("this instance element:", element);

                transclude(scope, function(clone){

                    $log.info("clone:", clone);

                });
            }
        }
    };
});