我对Angular2 RC5有问题 .
我的app.component(由app.module引导)看起来像这样,非常基本:
@Component({
selector: 'my-app',
template: `TEST`
})
export class AppComponent implements OnInit {
constructor() {
console.log("APP LOG!");
}
ngOnInit() {
console.log("APP INIT LOG!");
}
}
只要我在组件内部编写模板,它就可以正常工作 . 但是当我将它转移到自己的html文件并通过它包含它
templateUrl: 'app.component.html'
我遇到了一个无限循环 . 一遍又一遍地调用构造函数,从不到达ngOnInit . 无论我是尝试相对还是绝对路径都没有区别 . 没有ngModules在RC4上没有这个问题 .
相应的ngModule,也很基本:
@NgModule({
imports: [
BrowserModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule {}
我使用Meteor,所以一切都是使用Meteor angular2编译器编译的 .
任何提示都非常感谢!
1 回答
我不知道Meteor编译器,但看看文档:https://www.angular-meteor.com/tutorials/socially/angular2/dynamic-template
示例代码:https://github.com/Urigo/meteor-angular2.0-socially/archive/step_01.zip
告诉我们这样使用它: