简体   繁体   English

在主体上具有transclude的AngularJS渲染指令

[英]Angularjs rendering directive with transclude on body

I want to create a tooltip attribute directive with transclude, and render it on the body.. 我想创建一个带有transclude的tooltip属性指令,并将其呈现在主体上。

for example: 例如:

<div tooltip>
    <transcluded-content>content</transcluded-content>
</div>

module.directive('tooltip', function () {
    return {
            restrict: 'A',
            templateUrl: 'tooltip.html',
            transclude: {
                'transcluded-content': 'transcluded-content'
            }
        };
    });

I want to render the template on the body instead of the div... 我想在主体而不是div上渲染模板...

In order to have the element on the body, you could try moving it in the link function. 为了使元素在主体上,您可以尝试在链接功能中移动它。 How about this? 这个怎么样?

module.directive('tooltip', function () {
    return {
            restrict: 'A',
            templateUrl: 'tooltip.html',
            transclude: {
                'transcluded-content': 'transcluded-content'
            },
            link: function (scope, element) {
                angular.element('body').append(element);
            }
        };
    });

There are more complex approaches, but they'll require $compile -ing and other messy techniques. 有更复杂的方法,但是它们需要$compile -ing和其他凌乱的技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM