Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以编程方式将组件加载到angular 2中的一个div_Angular - Fatal编程技术网

如何以编程方式将组件加载到angular 2中的一个div

如何以编程方式将组件加载到angular 2中的一个div,angular,Angular,我对angular 2很陌生, 我有一组动态创建的div,我想根据用户选择将每个定义的组件加载到这些div中。我尝试了很多博客动态加载组件,但没有一个是清晰和简单的 我期望的是知道如何在单击按钮时将一个组件加载到div中 比如说 @Component({ selector: 'container', template: `<div id="container">// need to place the component here on click of a butt

我对angular 2很陌生, 我有一组动态创建的div,我想根据用户选择将每个定义的组件加载到这些div中。我尝试了很多博客动态加载组件,但没有一个是清晰和简单的

我期望的是知道如何在单击按钮时将一个组件加载到div中

比如说

@Component({
    selector: 'container',
    template: `<div id="container">// need to place the component here on click of a button  //</div>`
 })
@组件({
选择器:'容器',
模板:`//需要在单击按钮时将组件放置在此处//`
})

如果有人能提供plunker或解决方案,我们将不胜感激

使用#内部模板定义html组件

<div #container ></div>

这里有一个问答,如何做动态的东西,同样的东西,谢谢你的快速反应。这似乎很复杂,还有其他简单的例子吗?正如我在单击按钮时所说,它应该在容器上加载一个组件。您忘记定义
@ViewChild('container')
,否则就不会引用
#container
this.container.innerHTML="YOUR CONTENT";