AngularJS How to access elements inside directive before they get replaced

前端 未结 1 1011
灰色年华
灰色年华 2021-02-14 04:45

How do I get the input element from within the directive before the template overwrites the contents?

html

<
1条回答
  •  逝去的感伤
    2021-02-14 05:42

    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);
    
                    });
                }
            }
        };
    });
    

    0 讨论(0)
提交回复
热议问题