No provider for AuthHttp! when it's provided correctly
See original GitHub issueAt least I thought I was providing correctly. Below are the relevant snippets of my app.module file and the service in which I use AuthHttp. I followed the configuration in the ReadMe for creating the factory method to provide for AuthHttp, but there is a persisting issue with it not being recognized in my service. I’ve read the literature on nested dependency injections, and I feel as though I’m doing things correctly.
app.module.ts
import { provideAuth, AuthHttp, AuthConfig } from 'angular2-jwt';
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig(), http, options);
}
@NgModule({
declarations: [
AppComponent,
ButtonFormComponent,
...
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule,
AppRoutingModule
],
providers: [
{
provide: LocationStrategy,
useClass: HashLocationStrategy
},
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
},
employee.service.ts
import { AuthHttp } from 'angular2-jwt';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
import { ApiSettings } from './api-settings';
@Injectable()
export class EmployeeService {
api: String;
auth: String;
constructor(private http: Http, private authHttp: AuthHttp) {
this.api = ApiSettings.API;
this.auth = ApiSettings.Auth;
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:14
Top Results From Across the Web
No Provider for AuthHttp! Angular2-Jwt provider issue
I've read the literature on nested dependency injections, and I feel as though I'm doing things correctly. app.module.ts import { Http, ...
Read more >[Solved]-angular2-jwt No provider for AuthConfig-angular.js
Coding example for the question angular2-jwt No provider for AuthConfig-angular.js. ... You have to provide all injected dependencies in your NgModule . add ......
Read more >Auth http: No JWT present or has expired
When I'm trying to make an api call I get the response 401 (Unauthorized): No JWT present or has expired. in my app.module.ts,...
Read more >How to fix No provider for HttpClient error in Angular
To fix NullInjectorError: No provider for HttpClient! follow the below steps 1. Open `app.module.ts` file 2. Import HttpClientModule from ...
Read more >angular/angular - Gitter
no for real I don't know ... Because its provided by a DashboardModule that fails, but I also load ... or even comment...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I ran into the same issue and fought for days using Github and this repo. It turned out that the solution is very simple as I found on StackOverFlow: (https://stackoverflow.com/a/42064959):
In app.module.ts:
As simple as that!
You just have to import your auth.module in app.module.
app.module.ts
@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpModule, FormsModule, AuthModule // <----- Here is the auth.module class ], providers: [ AuthGuard, AlertService, AuthenticationService ], bootstrap: [AppComponent] })
export class AppModule { }