NullInjectorError: No provider for t! NullInjectorError: StaticInjectorError(ba)[Cw -> t]:
NullInjectorError: No provider for t! NullInjectorError: StaticInjectorError(ba)[Cw -> t]:
当我 运行 我的 Angular 8 应用程序的产品构建时,我在控制台中收到此错误。构建 运行 很好,我已经在我的提供商中包含了所有服务。
我已经运行执行了以下命令,但没有收到任何错误。
ng build --prod --optimization=false
有什么方法可以判断失败的原因吗?即使我注释掉所有提供者(预计构建失败),我仍然没有收到任何错误。
请让我知道我 can/should 提供了哪些其他信息来帮助您。谢谢!
错误信息:
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
//a bunch more components...
import { AccountModule } from './account/account.module';
import { AccountRoutingModule } from './account/account.routing.module';
import { AuthGuard } from './helpers/auth.guard';
import { ErrorInterceptor } from './helpers/error.interceptor';
import { JwtInterceptor } from './helpers/jwt.interceptor';
import { TemplateService } from './services/template.service';
import { ExerciseService } from './services/exercise.service';
import { ExamService } from './services/exam.service';
import { AuthService } from './services/auth.service';
import { FeatureService } from './services/feature.service';
import { RoleService } from './services/role.service';
import { UserService } from './services/user.service';
@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
HomeComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
AccountModule,
AccountRoutingModule,
RouterModule.forRoot([
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
//all routes left out for brevity
])
],
//entryComponents: [NewTemplateModal, NewExerciseModal, AddFeaturesModal, SaveSuccessComponent, ErrorComponent],
providers: [
AuthService,
ExamService,
ExerciseService,
FeatureService,
RoleService,
TemplateService,
UserService,
HttpClient,
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
],
bootstrap: [AppComponent]
})
export class AppModule { }
构建:
原来是个蠢货...
在我的一个组件中,我有 providers:[]
。一旦我完全删除它,它就开始工作了。
希望这可以帮助到其他人!
@Injectable({
providedIn: 'root'
})
export interface Cars {
number: number;
model: string;
owner: string;
ownerPhone: string;
}
对我来说,错误是我的@decorator 在服务中无效
当我 运行 我的 Angular 8 应用程序的产品构建时,我在控制台中收到此错误。构建 运行 很好,我已经在我的提供商中包含了所有服务。
我已经运行执行了以下命令,但没有收到任何错误。
ng build --prod --optimization=false
有什么方法可以判断失败的原因吗?即使我注释掉所有提供者(预计构建失败),我仍然没有收到任何错误。
请让我知道我 can/should 提供了哪些其他信息来帮助您。谢谢!
错误信息:
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
//a bunch more components...
import { AccountModule } from './account/account.module';
import { AccountRoutingModule } from './account/account.routing.module';
import { AuthGuard } from './helpers/auth.guard';
import { ErrorInterceptor } from './helpers/error.interceptor';
import { JwtInterceptor } from './helpers/jwt.interceptor';
import { TemplateService } from './services/template.service';
import { ExerciseService } from './services/exercise.service';
import { ExamService } from './services/exam.service';
import { AuthService } from './services/auth.service';
import { FeatureService } from './services/feature.service';
import { RoleService } from './services/role.service';
import { UserService } from './services/user.service';
@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
HomeComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
AccountModule,
AccountRoutingModule,
RouterModule.forRoot([
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
//all routes left out for brevity
])
],
//entryComponents: [NewTemplateModal, NewExerciseModal, AddFeaturesModal, SaveSuccessComponent, ErrorComponent],
providers: [
AuthService,
ExamService,
ExerciseService,
FeatureService,
RoleService,
TemplateService,
UserService,
HttpClient,
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
],
bootstrap: [AppComponent]
})
export class AppModule { }
构建:
原来是个蠢货...
在我的一个组件中,我有 providers:[]
。一旦我完全删除它,它就开始工作了。
希望这可以帮助到其他人!
@Injectable({
providedIn: 'root'
})
export interface Cars {
number: number;
model: string;
owner: string;
ownerPhone: string;
}
对我来说,错误是我的@decorator 在服务中无效