gpt4 book ai didi

Angular 6 StaticInjectorError : No provider for Options

转载 作者:太空狗 更新时间:2023-10-29 17:11:53 27 4
gpt4 key购买 nike

我最近将我的项目从 Angular5 更新到 Angular6。 该项目正在成功构建,但我在浏览器控制台中收到以下错误:

Unhandled Promise rejection: StaticInjectorError(AppModule)[options]: StaticInjectorError(Platform: core)[options]: NullInjectorError: No provider for options! ; Zone: ; Task: Promise.then ; Value: Error: StaticInjectorError(AppModule)[options]

关于如何调试这些问题有什么想法吗?

这是我的应用程序模块:

import { BrowserModule } from '@angular/platform-browser';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RouterModule, Routes } from '@angular/router';
import { CookieModule } from 'ngx-cookie';
import { PushNotificationsModule, PushNotificationsService } from 'ng-push';

// importing notifications module (angular 2 notifications)
import { SimpleNotificationsModule, NotificationsService } from 'angular2-notifications';

import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';

import { NgProgressModule } from '@ngx-progressbar/core';
import { NgProgressHttpClientModule } from '@ngx-progressbar/http-client';

import { GridModule } from './shared-modules/grid-module/grid.module';

// importing components
import { AppComponent } from './app.component';
import { LoginComponent } from './pages/login/login.component';
import { SampleRouteComponent } from './pages/sample-route/sample-route.component';

// services
import { GtmService } from './services/gtm/gtm.service';
import { AuthGuardService } from './services/auth-guard/auth-guard.service';
import { LoginService } from './services/login-service/login.service';
import { UserInfoService } from './services/user-info/user-info.service';
import { UtilityService } from './services/utility/utility.service';
import { IdleService } from './services/idle/idle.service';
import { GenericGridService } from './shared-modules/grid-module/generic-grid.service';
import { HttpInterceptorService } from './services/http-interceptor/http-interceptor.service';
import { ModalProviderService } from './services/modal-provider/modal-provider.service';
import { NotificationServiceService } from './services/notification-service.service';
import { Api } from './services/api';

const routes: Routes = [
{
path: 'login',
component: LoginComponent
},
{
path: 'sample-route',
component: SampleRouteComponent
},
{
path: '',
loadChildren: './shared-modules/container/container.module#ContainerModule',
canLoad: [AuthGuardService]
}
];

@NgModule({
declarations: [
AppComponent,
LoginComponent,
SampleRouteComponent
],
imports: [
BrowserModule,
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: false }),
BrowserAnimationsModule,
FormsModule,
HttpClientModule,
GridModule,
SimpleNotificationsModule,
CookieModule.forRoot(),
NgIdleKeepaliveModule.forRoot(),
NgProgressModule.forRoot(),
NgProgressHttpClientModule,
RouterModule.forRoot(routes, { initialNavigation: 'enabled' }),
PushNotificationsModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpInterceptorService,
multi: true
},
GtmService,
LoginService,
AuthGuardService,
UserInfoService,
UtilityService,
IdleService,
ModalProviderService,
NotificationsService,
GenericGridService,
NotificationServiceService,
Api,
PushNotificationsService
],
bootstrap: [AppComponent]
})
export class AppModule {

private loginObserver;

constructor(private loginService: LoginService, private utilityService: UtilityService, private idleService: IdleService,
private userInfoService: UserInfoService) {
this.loginService.checkLoggedIn();
this.loginObserver = this.loginService.loginObserver.subscribe(
loggedIn => {
if (loggedIn) {
const userdata: any = this.userInfoService.getUserInfo();
this.utilityService.createNotification({
title: 'Welcome!!',
content: `${userdata.vchDiplayName}`
});
this.idleService.reset();
this.loginObserver.unsubscribe();
}
}
);
}

}

最佳答案

这对于 OP 来说可能已经晚了,但我能够通过以下方式解决这个问题:

将必要的服务添加到我的供应商列表中 app.module.ts

希望对以后遇到这个问题的人有所帮助。

关于 Angular 6 StaticInjectorError : No provider for Options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50945067/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com