Sri
Sri

Reputation: 43

How to fix this error in Angular routing?

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

Answers (2)

Amin Kamalinia
Amin Kamalinia

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

Sathiya
Sathiya

Reputation: 239

Add the router-outlet to your app.component.html

<router-outlet></router-outlet> 

Upvotes: 1

Related Questions