diff --git a/components/empty/nz-embed-empty.component.html b/components/empty/nz-embed-empty.component.html
index 1304c4514d7..b1b3e13e11a 100644
--- a/components/empty/nz-embed-empty.component.html
+++ b/components/empty/nz-embed-empty.component.html
@@ -1,11 +1,11 @@
-
+
-
+
{{ content }}
-
+
diff --git a/components/empty/nz-embed-empty.component.ts b/components/empty/nz-embed-empty.component.ts
index 2fd593f7187..d6781cf6111 100644
--- a/components/empty/nz-embed-empty.component.ts
+++ b/components/empty/nz-embed-empty.component.ts
@@ -16,8 +16,8 @@ import {
import { DomSanitizer } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
-import { simpleEmptyImage, NzEmptyCustomContent, NzEmptySize, NZ_EMPTY_COMPONENT_NAME } from './nz-empty.config';
-import { NzEmptyContentTypeError } from './nz-empty.error';
+import { simpleEmptyImage, NzEmptyCustomContent, NzEmptySize, NZ_EMPTY_COMPONENT_NAME } from './nz-empty-config';
+import { getEmptyContentTypeError } from './nz-empty-error';
import { NzEmptyService } from './nz-empty.service';
@Component({
@@ -88,9 +88,7 @@ export class NzEmbedEmptyComponent implements OnChanges, OnInit, OnDestroy {
private renderEmpty(): void {
const content = this.content;
- if (content === undefined || content === null) {
- // Do nothing.
- } else if (typeof content === 'string') {
+ if (typeof content === 'string') {
this.contentType = 'string';
} else if (content instanceof TemplateRef) {
const context = { $implicit: this.nzComponentName } as any; // tslint:disable-line:no-any
@@ -102,7 +100,8 @@ export class NzEmbedEmptyComponent implements OnChanges, OnInit, OnDestroy {
this.contentType = 'component';
this.contentPortal = new ComponentPortal(content, this.viewContainerRef, injector);
} else {
- throw NzEmptyContentTypeError(content);
+ this.contentType = 'string';
+ this.contentPortal = undefined;
}
this.cdr.markForCheck();
diff --git a/components/empty/nz-empty.config.ts b/components/empty/nz-empty-config.ts
similarity index 100%
rename from components/empty/nz-empty.config.ts
rename to components/empty/nz-empty-config.ts
diff --git a/components/empty/nz-empty.error.ts b/components/empty/nz-empty-error.ts
similarity index 56%
rename from components/empty/nz-empty.error.ts
rename to components/empty/nz-empty-error.ts
index 04be36dbbcf..7a1a22e360c 100644
--- a/components/empty/nz-empty.error.ts
+++ b/components/empty/nz-empty-error.ts
@@ -1,3 +1,3 @@
-export function NzEmptyContentTypeError(content: any): Error { // tslint:disable-line:no-any
+export function getEmptyContentTypeError(content: any): Error { // tslint:disable-line:no-any
return TypeError(`[NG-ZORRO]: useDefaultContent expect 'string', 'templateRef' or 'component' but get ${content}`);
}
diff --git a/components/empty/nz-empty.component.ts b/components/empty/nz-empty.component.ts
index 24df0312e4c..ac3cdfe5bdd 100644
--- a/components/empty/nz-empty.component.ts
+++ b/components/empty/nz-empty.component.ts
@@ -9,7 +9,7 @@ import {
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
-import { emptyImage } from './nz-empty.config';
+import { emptyImage } from './nz-empty-config';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
diff --git a/components/empty/nz-empty.service.ts b/components/empty/nz-empty.service.ts
index 3c87356eb2b..6c140f88a0c 100644
--- a/components/empty/nz-empty.service.ts
+++ b/components/empty/nz-empty.service.ts
@@ -1,6 +1,7 @@
-import { Inject, Injectable, Optional, Type } from '@angular/core';
+import { Inject, Injectable, Optional, TemplateRef, Type } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
-import { NzEmptyCustomContent, NZ_DEFAULT_EMPTY_CONTENT } from './nz-empty.config';
+import { NzEmptyCustomContent, NZ_DEFAULT_EMPTY_CONTENT } from './nz-empty-config';
+import { getEmptyContentTypeError } from './nz-empty-error';
@Injectable({
providedIn: 'root'
@@ -15,7 +16,16 @@ export class NzEmptyService { // tslint:disable-line:no-any
}
setDefaultContent(content?: NzEmptyCustomContent): void {
- this.userDefaultContent$.next(content);
+ if (typeof content === 'string'
+ || content === undefined
+ || content === null
+ || content instanceof TemplateRef
+ || content instanceof Type
+ ) {
+ this.userDefaultContent$.next(content);
+ } else {
+ throw getEmptyContentTypeError(content);
+ }
}
resetDefault(): void {
diff --git a/components/empty/nz-empty.spec.ts b/components/empty/nz-empty.spec.ts
index cc3298dcf1a..34addd76ad7 100644
--- a/components/empty/nz-empty.spec.ts
+++ b/components/empty/nz-empty.spec.ts
@@ -1,11 +1,11 @@
import { CommonModule } from '@angular/common';
-import { Component, Inject, NgModule, OnInit, TemplateRef, ViewChild } from '@angular/core';
+import { Component, Inject, NgModule, TemplateRef, ViewChild } from '@angular/core';
import { fakeAsync, tick, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NzListModule } from '../list';
import { NzEmbedEmptyComponent } from './nz-embed-empty.component';
+import { NZ_DEFAULT_EMPTY_CONTENT, NZ_EMPTY_COMPONENT_NAME } from './nz-empty-config';
import { NzEmptyComponent } from './nz-empty.component';
-import { NZ_DEFAULT_EMPTY_CONTENT, NZ_EMPTY_COMPONENT_NAME } from './nz-empty.config';
import { NzEmptyModule } from './nz-empty.module';
import { NzEmptyService } from './nz-empty.service';
@@ -145,6 +145,13 @@ describe('nz-empty', () => {
expect(embedComponent).toBeTruthy();
expect(emptyComponent).toBeFalsy();
expect(embedComponent.nativeElement.innerText).toBe('list');
+
+ // Null.
+ testComponent.noResult = null;
+ refresh();
+ expect(embedComponent).toBeTruthy();
+ expect(emptyComponent).toBeFalsy();
+ expect(embedComponent.nativeElement.innerText).toBe('');
}));
it('should support string, template and component', fakeAsync(() => {
@@ -279,7 +286,7 @@ export class NzEmptyTestBasicComponent {
export class NzEmptyTestServiceComponent {
@ViewChild('tpl') template: TemplateRef;
- noResult = null;
+ noResult = undefined;
constructor(private emptyService: NzEmptyService) {
}
diff --git a/components/empty/public-api.ts b/components/empty/public-api.ts
index edd144618d4..3ff9dfd934c 100644
--- a/components/empty/public-api.ts
+++ b/components/empty/public-api.ts
@@ -2,4 +2,4 @@ export * from './nz-embed-empty.component';
export * from './nz-empty.component';
export * from './nz-empty.module';
export * from './nz-empty.service';
-export * from './nz-empty.config';
+export * from './nz-empty-config';