我有问题让我的应用程序通过路由链接在一起我相信。一旦我添加了<router-outlet>
,我就开始出现两次标题显示和控制台错误的问题:
EXCEPTION: Error in ./AppComponent class AppComponent - inline template:5:1 caused by: No provider for Customer!
以下是我所拥有的内容,我也将其发布在git HERE
上伍-模块
@NgModule({
declarations: [
AppComponent, LibraryComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([
{path: 'home', component: AppComponent},
{path: 'mainPage', component: LibraryComponent},
{path:'**', redirectTo: 'home', pathMatch: 'full'}
])
],
providers: [
BooksService,
CustomerService,
],
bootstrap: [AppComponent]
})
export class AppModule {
}
AppComponent:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['app/css/bootstrap.css'],
})
export class AppComponent {
title = "Dummy login page"
}
app.component.html
<div class="container">
<h1>
{{title}}
</h1>
<app-library></app-library>
</div>
app library component:
@Component({
selector: 'app-library',
templateUrl: 'app/library/homePage/mainPage.html',
styleUrls: ['app/css/bootstrap.css'],
})