Reputation: 119
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)
Upvotes: 3
Views: 20142
Reputation: 2077
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.
Upvotes: 1
Reputation: 1
Try changing Http to HttpClient as noted in the Angular Update guide https://update.angular.io/
Upvotes: -1
Reputation: 2590
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
Upvotes: 8