【发布时间】:2017-07-09 17:29:49
【问题描述】:
我正在尝试创建一个插件,该插件将组件作为参数并在正文标记的末尾呈现其内容。就像使用 jQuery 的插件一样。
@Component({
selector: 'some-selector',
template: 'This is FirstComponent'
})
class FirstComponent{}
@Component({
selector: 'app',
template: 'The root component'
})
class AppComponent{
// ImaginaryModalOpener is what i want to achieve.
// a standalone function that can take a component and render it in dom
// at the bottom of the body tag
ImaginaryModalOpener(FirstComponent);
}
我已经看到了很多关于渲染动态组件的 stackoverflow 问题,但它们在根组件中使用指令或 HTML 标记开始。 在我的情况下,根模板将没有 ImaginaryModalOpener 的指令或组件。
如果我遗漏了什么,请指出。
【问题讨论】:
-
this answer 应该为您提供解决方案,它不会让用户查看容器 ref,而是使用直接 DOM 节点将组件插入
标签: angular dependency-injection