我改变了我的路线,以便我的主页是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 :(得分:1)
AppComponent
不应该是路由组件。相反,它应该只是您的应用程序的入口点。这意味着,模板应该至少在其某些部分包含router outlet
,app组件的css选择器应该在index.html文件中,AppComponent
应该在{{{}内部声明1}}你的列表bootstrap
。
有关详细信息,请参阅this SO question