【发布时间】:2016-12-15 07:25:19
【问题描述】:
我有一个这样的 angular2 组件:
@Component({
selector: 'demo',
template: `
<div [innerHTML]="content"></div>
`;
})
export class demoComponent {
@Input() step: string;
private content: string = '';
ngOnInit () {
if (this.step === "foo") {
this.content = "bar";
}
}
}
我想使用一些逻辑来决定最合适的模板进行渲染。我在 myDomain.com/templates 上有一系列由 express 提供的静态 html 文件。所以我需要能够“读取”./templates/xyz.html 到我的 ng2 组件中的字符串。类似于 nodeJS 中的fs.ReadFileSync API。我怎样才能做到这一点? HTTP 调用?文件阅读器?
【问题讨论】:
标签: node.js http angular angular2-template