Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANGULAR 4 routing issue: No provider for HttpClient

Hi I have a login component that contains link to the register component.

When I click on this link I got this issue:

ERROR Error: Uncaught (in promise): Error: No provider for HttpClient!
Error: No provider for HttpClient!
at injectionError (core.es5.js:1169)
at noProviderError (core.es5.js:1207)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._throwOrNull (core.es5.js:2649)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/co...

The login component is well loaded, the register fails.

on the login component html I have:

 <a [routerLink]="['/register']" class="btn btn-link">Register</a>

my app routing looks like this:

 const appRoutes: Routes = [
{ path: '', component: HomeComponent, canActivate: [GuardService] },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },

// otherwise redirect to home
{ path: '**', redirectTo: '' }
];

export const routing = RouterModule.forRoot(appRoutes);

The versions I am using: Node.js version: v8.5.0 NPM version: 5.4.2

Thanks!

like image 574
b.lopes Avatar asked Aug 15 '26 05:08

b.lopes


1 Answers

Ensure HttpClientModule is listed in imports:

@NgModule({
  imports: [BrowserModule, HttpClientModule, ...],
})
export class AppModule{}

See also https://angular.io/api/common/http/HttpClient

like image 130
Günter Zöchbauer Avatar answered Aug 16 '26 18:08

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!