我对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-compiler编译的。
任何提示都非常感谢!
答案 0 :(得分:0)
I dont know that Meteor compiler, but taking a look at the documentation: https://www.angular-meteor.com/tutorials/socially/angular2/dynamic-template
Example-Code: https://github.com/Urigo/meteor-angular2.0-socially/archive/step_01.zip
Tells us to use it like this:
import { Component } from '@angular/core';
import template from './app.component.html';
@Component({
selector: 'app',
template
})
export class AppComponent {}