Reputation: 43
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {HomeComponent} from "./home/home.component";
import {SettingsComponent} from "./settings/settings.component";
const routes: Routes = [
{path: 'home', component: HomeComponent},
{path: 'settings', component: SettingsComponent},
{path: '', redirectTo: 'home', pathMatch: 'full'
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
export const routingComponents = [HomeComponent, SettingsComponent]
It works very well but when I add private homeservice: HomeService
to the constructor of my home.component.ts
, my app starts to show me a white page in the app.component.html
and I can't do anything. How can I fix this routing problem?
Upvotes: 2
Views: 408
Reputation: 334
I believe you did not add HomeService in module. You can add it in Provider section of the module. So I think it solves your problem
providers: [ HomeService ]
Upvotes: 0
Reputation: 239
Add the router-outlet to your app.component.html
<router-outlet></router-outlet>
Upvotes: 1