StaticInjectorError(平台:核心)[Config]:NullInjectorError:没有Config的提供者! NullInjectorError:StaticInjectorError(AppModule)[Config]:

时间:2019-09-05 11:11:59

标签: typescript angular8

我是Angular8的新手,我正在使用jwthelper编码jwt令牌并提取细节。 我需要在我的angular 8项目中实现JwtModule。 我正在Angular8的app.module.ts中导入JwtModule。 如果我运行ng serve,则会收到上述错误。

ERROR Error: StaticInjectorError(AppModule)[Config]: 
  StaticInjectorError(Platform: core)[Config]: 
    NullInjectorError: No provider for Config!
        at NullInjector.get (core.js:778)
    at resolveToken (core.js:2564)
    at tryResolveToken (core.js:2490)
    at StaticInjector.get (core.js:2353)
    at resolveToken (core.js:2564)
    at tryResolveToken (core.js:2490)
    at StaticInjector.get (core.js:2353)
    at resolveNgModuleDep (core.js:26403)
    at _createClass (core.js:26475)
    at _createProviderInstance (core.js:26436)
ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[Config]: 
  StaticInjectorError(Platform: core)[Config]: 
    NullInjectorError: No provider for Config!
NullInjectorError: StaticInjectorError(AppModule)[Config]: 
  StaticInjectorError(Platform: core)[Config]: 
    NullInjectorError: No provider for Config!

请提出解决方案。

本地存储中有一个令牌:

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImFjMTUyNzZhZjA2MjU1YTdlMDM0MmQ5ODg4N2M1ZmI2ZWNmM2RlNGUyNjhmYTc4MTliODRhOTVmMmJiNGZiMTliMDFkNjBhNWRlNjhlN2VlIn0.eyJhdWQiOiJmMDExY2M1OC00MGNlLTQzYTktOGY3MS04NDI0OTRlM2E5OTciLCJqdGkiOiJhYzE1Mjc2YWYwNjI1NWE3ZTAzNDJkOTg4ODdjNWZiNmVjZjNkZTRlMjY4ZmE3ODE5Yjg0YTk1ZjJiYjRmYjE5YjAxZDYwYTVkZTY4ZTdlZSIsImlhdCI6MTUyMzI5NzkzNSwibmJmIjoxNTIzMjk3OTM1LCJleHAiOjE1MjMyOTgyMzUsInN1YiI6IjIiLCJzY29wZXMiOlsiYXV0aGVudGljYXRlZCIsImFuZ3VkcnUiXX0.RNY2Yb9xiJDcER4rtHEAYMmoLyvPYij-upZc97q-mSgICKE6_xWih_IBjY4cHQXkkiRyCXaqCfwfMM4YWVjv7bsMlLN5bWlH0JTeYoYf2gENLBIG51NwGpU3iAl8KG_51ljZKbs3RE_ULDbphM1NG8BhobVQ5RlObWzejrkPcMHqlGJaMOMLQuXC1iBR2jI9tlfiP4RD4FUUsRkUEUJ5PSIRl34jWoTv31SSf1bkv43q3YeKTfk6pXZ5Ft_eV8G871KkmQSHANAn26A5ujj2FOh-uCV_VNJ97RuTQ6J4NP2YB-mMaWYpZ1xF-4ndqafRGFXJ_8euBO4cA36zvP3B7g

这是我的app.module.ts:

//This is my app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform- 
browser/animations';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import { JwtModule , JWT_OPTIONS , JwtModuleOptions , 
JwtHelperService} from '@auth0/angular-jwt';
//routing
import { AppRoutingModule } from './app-routing.module';
//components
import { AppComponent } from './app.component';
//modules
import { PortalModule } from './portal/portal.module';
import { LandingPageModule } from './landing-page/landing- 
page.module';
import { NbThemeModule, NbLayoutModule } from '@nebular/theme';
import { NbEvaIconsModule } from '@nebular/eva-icons';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
//services
import { AuthService } from '../app/services/auth/auth.service';
import { GlobalsService } from  '../app/services/globals.service';
import { UsersComponent } from './users/users.component';
import { SharedModule } from './shared/shared.module';
const JWT_Module_Options: JwtModuleOptions = {
   config: {
   tokenGetter: tokenGetter,
   whitelistedDomains: []
   }
};
@NgModule({
declarations: [
AppComponent,
UsersComponent,
  ],
imports: [
   BrowserModule,
   BrowserAnimationsModule,
   HttpClientModule,
   HttpModule,
   FormsModule,
   ReactiveFormsModule,
   AppRoutingModule,
   PortalModule.forRoot(),
   LandingPageModule,
   NbThemeModule.forRoot({ name: 'default' }),
   NbLayoutModule,
   NbEvaIconsModule,
   SharedModule,
   JwtModule.forRoot(JWT_Module_Options)    
   ],
   providers: [
     AuthService,
     GlobalsService,
     JwtHelperService
     ],

  bootstrap: [AppComponent]
   })
  export class AppModule { }
  export function tokenGetter() {
       return localStorage.getItem("access_token");
  }

0 个答案:

没有答案