2016-08-23 7 views
1

私はrc4からrc.5に自分のng2アプリをアップグレードするだけです。 私app.htmlで何している。そして、このエラーが発生したangular2複数のコンポーネントエラー

@NgModule({ 
    imports: [ 
    ] 
    declarations: [ 
     SwitchAppComponent 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { 
} 

<div> 
    <switch-app [account]="cache.accountInfo" [app]="cache.current_app"> 
    <router-outlet></router-outlet> 
</div> 

私はapp.module.tsでSwitchAppComponent宣言私がチェック

More than one component: AppComponent,SwitchAppComponent 

[ERROR ->]<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app> 

を私app、AppComponentとSwitchAppComponentのセレクタは違いです。ここ

は、2つのコンポーネントの簡単なコードです: アプリ成分:

@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);} 
} 
+0

私はAppComponentを属性[app]で宣言していますが、switch-appコンポーネントを挿入すると、[app]属性がその入力として使用されます。私がswitch-appの[app] attrを変更する限り、すべてのことは正しい – shun

答えて

3

問題があります:

<switch-app [account]="cache.accountInfo" [app]="cache.current_app"></switch-app> 

これはswitch-appセレクタと[app]セレクタの両方に一致しますまたは両方ともコンポーネントのセレクタです。 Angularでは、同じ要素に2つのコンポーネントを使用できません。

ここで何をしようとしているのか分かりませんが、1つのコンポーネントが代わりにディレクティブになる必要がありますか?

関連する問題