2017-06-05 17 views
0

をロードするための第一出口を見つけることができません私のホームページがappcomponentあるように私は私のルートを変更し、そして今、私はこのエラーを取得しています:エラー:(約束で)キャッチされない:エラー:「AppComponent」

Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'AppComponent' 

これが何であるかについてのいかなる考え?

マイルート:

import {Routes} from "@angular/router"; 
import {PatientComponent} from "./patient/patient.component"; 
import {AppComponent} from "./app.component"; 



export const routes: Routes = [ 
    {path: '', component: AppComponent}, 
    {path: 'patient/:id', component: PatientComponent}, 

]; 

私のアプリのコンポーネントは:

import {Component, OnInit} from '@angular/core'; 
import {AfdelingService} from './afdeling.service'; 
import {PatientService} from './patient.service'; 
import 'rxjs/Rx'; 
import {Router} from "@angular/router"; 


@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'], 
    providers: [AfdelingService, PatientService] 
}) 
export class AppComponent implements OnInit { 
    errorMessage: string; 
    afdeling = []; 

    constructor(private afdelingService: AfdelingService, private router: Router) { 
    } 

    ngOnInit() { 
    this.getData() 
    } 

    goToAfdeling(afdeling) { 
    console.log(afdeling.afdelingsNaam); 
    this.router.navigate(["/afdelingen", afdeling.afdelingsNaam]); 
    } 

    getData() { 
    this.afdelingService.getAfdelingen() 
     .subscribe(
     data => { 
      this.afdeling = data; 
      console.log(this.afdeling); 
     }, error => this.errorMessage = <any> error); 


    } 
} 
+0

アプリのコンポーネントは、アプリケーションのシェルでなければなりませんし、ルーティング対象ではありません。 – DeborahK

+0

上記のコメントに追加する...あなたは経路の内容を表示するためにルータのアウトレットを定義する必要があります... – Lambo14

答えて

1

AppComponentルーティングコンポーネントすべきではありません。代わりに、アプリケーションのエントリポイントにする必要があります。つまり、テンプレートには少なくとも一部にrouter outletが含まれている必要があります.appコンポーネントのCSSセレクタはindex.htmlファイルにあり、AppComponentはリストの中でAppModuleの中に宣言する必要があります。

は、詳細はthis SO questionを参照してください

関連する問題