Ilj*_*lja 38 javascript angular
我有以下应用程序结构
app
home
home.html
home.ts
home.sass
app.component.ts
index.html
Run Code Online (Sandbox Code Playgroud)
基本上我想将我的页面划分为单独的文件夹,这些文件夹具有与它们相关的样式,.ts和.html文件
但是现在加载这样的模板
import {Component} from 'angular2/core';
@Component({
selector: 'admin-app',
template: 'home/home.html'
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
文学加载"home/home.html"字符串作为模板,因为我想要home.html文件的html内容.
Mic*_*rdi 69
我想如果你想传递一个模板,你应该使用
templateUrl: 'home/home.html'
Run Code Online (Sandbox Code Playgroud)
这应该发出一个http请求并将html加载到您的组件中.
小智 8
您可能需要考虑使用Webpack.在这种情况下,你只需:
@Component({
selector: 'my-comp',
template: require('./mycomp.component.html')
})
Run Code Online (Sandbox Code Playgroud)
到目前为止,我发现它是一个可靠的解决方案,因为如果URL不正确,它实际上会抛出编译时错误.
| 归档时间: |
|
| 查看次数: |
27574 次 |
| 最近记录: |