3

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);}
}
1
  • i found the problem, cause i declare my AppComponent with an attribute [app], but when i insert the switch-app component into it, i use an [app] attribute as Input of it. as long as i change the [app] attr of switch-app, all thing is right Commented Aug 23, 2016 at 9:37

1 Answer 1

6

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 ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.