1
我只是将我的ng2应用程序从rc.4升级到rc.5。 在我app.html是什么:angular2多个组件错误
<div>
<switch-app [account]="cache.accountInfo" [app]="cache.current_app">
<router-outlet></router-outlet>
</div>
我宣布在app.module.ts的SwitchAppComponent:
@NgModule({
imports: [
]
declarations: [
SwitchAppComponent
],
bootstrap: [AppComponent]
})
export class AppModule {
}
再发生这样的错误:
More than one component: AppComponent,SwitchAppComponent
[ERROR ->]<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app>
我检查了我应用程序,AppComponent和SwitchAppComponent的选择器是不同的。
这里是两个组件的简单代码: 应用组分:
@Component({
selector: '[app]',
styleUrls: ['./app.css', './custom.scss'],
encapsulation: ViewEncapsulation.None,
templateUrl: './app.html'
})
export class AppComponent extends CommonComponent implements OnInit {
cache = cache;
}
开关应用组件:
@Component({
selector: 'switch-app',
templateUrl: './switch-app.html'
})
export class SwitchAppComponent implements OnInit {
@Input('app') app;
@Input('account') account;
ngOnInit() { console.log(this.account, this.app);}
}
我发现这个问题,导致我用一个属性[app]声明我的AppComponent,但是当我插入switch-app组件时,我使用[app]属性作为它的输入。只要我改变switch-app的[app] attr,所有的事情都是正确的 – shun