angular2 More than one component error
11,198
The issue is there:
<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app>
This matches both the switch-app
selector, and the [app]
selector, both being selectors for a component. Angular cannot use 2 components on the same element.
Not sure what you are trying to do here, maybe one component should be a directive instead ?
Author by
shun
Updated on June 04, 2022Comments
-
shun almost 2 years
i just upgrade my ng2 app from rc.4 to rc.5. what in my app.html is:
<div> <switch-app [account]="cache.accountInfo" [app]="cache.current_app"> <router-outlet></router-outlet> </div>
i declare the SwitchAppComponent at app.module.ts:
@NgModule({ imports: [ ] declarations: [ SwitchAppComponent ], bootstrap: [AppComponent] }) export class AppModule { }
then this error has occurred:
More than one component: AppComponent,SwitchAppComponent [ERROR ->]<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app>
i checked my app, the selector of AppComponent and SwitchAppComponent is difference.
here is a brief codes of the two component: 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:
@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);} }