[英]angular2 More than one component error
我只是將我的ng2應用程序從rc.4升級到rc.5。 我app.html中的內容是:
<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的選擇器是不同的。
這里是兩個組件的簡要代碼:app-component:
@Component({
selector: '[app]',
styleUrls: ['./app.css', './custom.scss'],
encapsulation: ViewEncapsulation.None,
templateUrl: './app.html'
})
export class AppComponent extends CommonComponent implements OnInit {
cache = cache;
}
switch-app組件:
@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);}
}
問題在於:
<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app>
這與switch-app
選擇器和[app]
選擇器都匹配,兩者都是組件的選擇器。 Angular不能在同一元素上使用2個組件。
不知道你在這里想做什么,也許一個組件應該是一個指令呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.