我有一个部件角2插入到@Component另一组件
import { Component } from '@angular/core';
@Component({
selector: 'test-component',
template: '<b>Content</b>',
})
export class TestPage {
constructor() {}
}
的DOM我有另一种组分:
import { Component } from '@angular/core';
@Component({
selector: 'main-component',
templateUrl: 'main.html',
})
export class MainPage {
constructor() {}
putInMyHtml() {
}
}
main.html中:
<p>stuff</p>
<div> <!-- INSERT HERE --> </div>
我如何动态地将我的TestPage
组件插入<!--INSERT HERE-->
编程的区域,如wh我运行putInMyHtml
。
我尝试编辑DOM并插入<test-component></test-component>
,但它不显示TestPage模板中的内容文本。
[在角2无法初始化动态追加(HTML)组件(可能的重复http://stackoverflow.com/questions/36566698/cant- initialize-dynamic-html-component-in-angular-2) – echonax
这是正确的解决方案。您是否在浏览器控制台或编译器中收到错误消息? – Martin
@Martin没有错误,它仍然在DOM中的没有角度渲染模板。 –
Akshat