I'm new to an Angular-based UI project, and used vscode to generate two new components for use on the project. However, I keep getting errors whenever I push my changes to git(bitbucket) and these errors are not present when I build the project on my machine. Where do I need to provide HttpClient/HttpClientModule so that these new components can use HttpHandler?
I've added providers for HttpClientModule and HttpClient on both app.module.ts and the new components themselves.
modal-wiped-all.component.ts
import { Component, OnInit } from '@angular/core';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Router } from '@angular/router';
import { OrganisationsApiService } from 'src/app/api/organisations/organisations-api.service';
import { HttpClient, HttpClientModule, HttpHandler } from '@angular/common/http';
@Component({
selector: 'app-modal-wipedall',
templateUrl: './modal-wiped-all.component.html',
providers: [NgbActiveModal,
OrganisationsApiService,
HttpClientModule,
HttpClient,
]})
cleanup.component.ts
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpClientModule, HttpHandler } from '@angular/common/http';
import { OrganisationsApiService } from 'src/app/api/organisations/organisations-api.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ModalWipedAllComponent } from '../modal/modal-wiped-all/modal-wiped-all.component';
@Component({
selector: 'app-cleanup',
templateUrl: './cleanup.component.html',
styleUrls: ['./cleanup.component.css'],
providers: [OrganisationsApiService,
NgbModal,
HttpClientModule,
HttpClient,
]
})
export class CleanupComponent implements OnInit {
submitted: boolean;
loading: boolean;
deleted: number;
constructor(
private http: HttpClient,
private api: OrganisationsApiService,
private modalService: NgbModal) {
}
app.module.ts providers
providers: [AwsApiService,
OrganisationsApiService,
LabsApiService,
UsersApiService,
UserManagementDataService,
ConfigDataService,
ErrorDataService,
DeploymentResponseDataService,
ModalOptionsComponent,
ModalConfigurationComponent,
ModalUndeployLabComponent,
ModalCreatedUserComponent,
NgbActiveModal,
HttpClientModule,
HttpClient,
{ provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptor,
multi: true}
],
error messages:
CleanupComponent.CleanupComponent should createChrome 56.0.2924 (Linux 0.0.0)
<1s
Error: StaticInjectorError(DynamicTestModule)[HttpClient -> HttpHandler]:
StaticInjectorError(Platform: core)[HttpClient -> HttpHandler]:
NullInjectorError: No provider for HttpHandler!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get node_modules/@angular/core/fesm5/core.js:1062:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1300:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1244:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1141:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1300:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1244:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1141:1)
at resolveNgModuleDep node_modules/@angular/core/fesm5/core.js:8369:1)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get node_modules/@angular/core/fesm5/core.js:9057:1)
at resolveDep node_modules/@angular/core/fesm5/core.js:9422:1)
ModalWipedAllComponent.ModalWipedAllComponent should createChrome 56.0.2924 (Linux 0.0.0)
<1s
Error: StaticInjectorError(DynamicTestModule)[HttpClient -> HttpHandler]:
StaticInjectorError(Platform: core)[HttpClient -> HttpHandler]:
NullInjectorError: No provider for HttpHandler!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get node_modules/@angular/core/fesm5/core.js:1062:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1300:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1244:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1141:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1300:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1244:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1141:1)
at resolveNgModuleDep node_modules/@angular/core/fesm5/core.js:8369:1)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get node_modules/@angular/core/fesm5/core.js:9057:1)
at resolveDep node_modules/@angular/core/fesm5/core.js:9422:1)
I expect the project to build as it does locally, I instead get NullInjectorErrors
UPDATE: component.spec.ts files ModalWipedAll
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ModalWipedAllComponent } from './modal-wiped-all.component';
describe('ModalWipedAllComponent', () => {
let component: ModalWipedAllComponent;
let fixture: ComponentFixture<ModalWipedAllComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ModalWipedAllComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ModalWipedAllComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
CleanupComponent
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CleanupComponent } from './cleanup.component';
describe('CleanupComponent', () => {
let component: CleanupComponent;
let fixture: ComponentFixture<CleanupComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CleanupComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CleanupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});