【发布时间】:2016-01-17 21:54:49
【问题描述】:
我根据 angular.io 入门项目使用种子结构。到目前为止一切正常。
现在我想更改顶部组件以从单独的文件中查看视图,但我遇到了麻烦。工作代码是:
import {Component, View} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>Angular2</h1>',
directives: []
})
export class AppComponent {
constructor() {
}
}
然后我将模板更改为 templateUrl,如下所示:
templateUrl: 'app.component.html',
我在这个文件中的代码与以前完全相同
<h1>Angular2</h1>
似乎很明显可以工作,但事实并非如此。它不会吐出错误,但除了入门演示中的“正在加载....”消息外不显示任何内容
感谢您的帮助
彼得
【问题讨论】:
-
您确定您的模板在正确的目录中吗?如果它与组件在同一目录中,则应为
templateUrl: 'app/app.component.html', -
尝试将 templateUrl 放入 @View 装饰器中。
-
谢谢,'app/app.component.html' 更正解决了这个问题。原因尚不清楚。 templateUrl 是否引用了项目根目录?