3
votes

When I run cmd in angular ng serve, the application stops loading and I get the error below.

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[AuthService -> Http]: StaticInjectorError(Platform: core)[AuthService -> Http]: NullInjectorError: No provider for Http! Error: StaticInjectorError(AppModule)[AuthService -> Http]: StaticInjectorError(Platform: core)[AuthService -> Http]: NullInjectorError: No provider for Http! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979) at resolveToken (core.js:1232)

3
post your code for auth service - Sajeetharan

3 Answers

8
votes

You have to register your DI in module/component level. Otherwise you can see this type of error message.

import { NgModule } from '@angular/core';

import { AuthService } from 'PATH';

@NgModule({
  providers: [AuthService],
})
export class YOURMODULE{
}

Read more about providers: https://angular.io/guide/providers

1
votes

Static Injector Error normally rises when a class is defined and is not available for execution for the root module. For example you have Class A is the parent module of Class B and Class C. Class C is being accessed inside Class B but Class C is not defined as a provider inside parent, in this case this error would pop-up.

For your particular case : AuthService is the child and its not added as the provider in AuthModule.

import { AuthService } from './Path';

and add AuthService in providers array would fix issue.

-1
votes

Try changing Http to HttpClient as noted in the Angular Update guide https://update.angular.io/