使用templateUrl的Angular2 RC5无限循环



我在使用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编译器编译的。

任何提示都非常感谢!

我不知道流星编译器,但看看文档:https://www.angular-meteor.com/tutorials/socially/angular2/dynamic-template

示例代码:https://github.com/Urigo/meteor-angular2.0-socially/archive/step_01.zip

告诉我们这样使用:

import { Component } from '@angular/core';
import template from './app.component.html';
@Component({
  selector: 'app',
  template
})
export class AppComponent {}

最新更新