shun
shun

Reputation: 245

angular2 More than one component error

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);}
}

Upvotes: 3

Views: 11515

Answers (1)

Philippe Plantier
Philippe Plantier

Reputation: 8073

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 ?

Upvotes: 6

Related Questions