Skip to content

Commit

Permalink
feat(module:upload): using optional HttpClientModule (#931)
Browse files Browse the repository at this point in the history
close #934  close #926
  • Loading branch information
cipchk authored and vthinkxie committed Jan 20, 2018
1 parent d70af03 commit 9bf9752
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/upload/nz-upload-btn.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-any ordered-imports
import { Component, ViewChild, ElementRef, HostListener, OnInit, OnChanges, OnDestroy, SimpleChange, SimpleChanges, ChangeDetectorRef, Input, Renderer2 } from '@angular/core';
import { Component, ViewChild, ElementRef, HostListener, OnInit, OnChanges, OnDestroy, SimpleChange, SimpleChanges, ChangeDetectorRef, Input, Renderer2, Optional } from '@angular/core';
import { HttpClient, HttpRequest, HttpEventType, HttpResponse, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
Expand Down Expand Up @@ -223,7 +223,9 @@ export class NzUploadBtnComponent implements OnInit, OnChanges, OnDestroy {
}
// endregion

constructor(private http: HttpClient, private _el: ElementRef, private _renderer: Renderer2, private cd: ChangeDetectorRef) {}
constructor(@Optional() private http: HttpClient, private _el: ElementRef, private _renderer: Renderer2, private cd: ChangeDetectorRef) {
if (!http) throw new Error(`Not found 'HttpClient', You can import 'HttpClientModel' in your root module.`);
}

ngOnInit(): void {
this.inited = true;
Expand Down
3 changes: 1 addition & 2 deletions src/components/upload/nz-upload.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NzLocaleModule } from '../locale/index';
Expand All @@ -10,7 +9,7 @@ import { NzUploadListComponent } from './nz-upload-list.component';
import { NzUploadComponent } from './nz-upload.component';

@NgModule({
imports: [CommonModule, FormsModule, HttpClientModule, NzToolTipModule, NzProgressModule, NzLocaleModule],
imports: [CommonModule, FormsModule, NzToolTipModule, NzProgressModule, NzLocaleModule],
declarations: [NzUploadComponent, NzUploadBtnComponent, NzUploadListComponent],
exports: [NzUploadComponent]
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/upload/nz-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { Component, Injector, ViewChild, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { NzLocaleModule } from '../locale/nz-locale.module';
import { NzUploadModule } from './nz-upload.module';
import { NzUploadComponent } from './nz-upload.component';
Expand All @@ -12,7 +13,7 @@ describe('NzUpload', () => {
let instance: TestComponent;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ NzUploadModule ],
imports: [ HttpClientModule, NzUploadModule ],
declarations: [ TestComponent ]
});
fixture = TestBed.createComponent(TestComponent);
Expand Down

0 comments on commit 9bf9752

Please sign in to comment.