【发布时间】:2017-03-26 20:20:12
【问题描述】:
我有一个组件
import { Component } from '@angular/core';
@Component({
selector: 'test-component',
template: '<b>Content</b>',
})
export class TestPage {
constructor() {}
}
我还有另一个组件:
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--> 以编程方式运行的区域中,就像我运行putInMyHtml 时一样。
我尝试编辑 DOM 并插入 <test-component></test-component>,但它不显示来自 TestPage 模板的内容文本。
【问题讨论】:
-
这是正确的解决方案。您是否在浏览器控制台或编译器中收到错误消息?
-
@Martin 没有错误,它在 DOM 中保持为
没有角度渲染模板。
标签: javascript angular