diff --git a/components/badge/nz-badge.component.html b/components/badge/nz-badge.component.html
index 96a35f0429c..32c16a3c874 100644
--- a/components/badge/nz-badge.component.html
+++ b/components/badge/nz-badge.component.html
@@ -6,8 +6,9 @@
{{ nzText }}
;
checkContent(): void {
- if (isEmpty(this.contentElement.nativeElement)) {
+ this.notWrapper = isEmpty(this.contentElement.nativeElement);
+ if (this.notWrapper) {
this.renderer.addClass(this.elementRef.nativeElement, 'ant-badge-not-a-wrapper');
} else {
this.renderer.removeClass(this.elementRef.nativeElement, 'ant-badge-not-a-wrapper');
@@ -89,7 +94,13 @@ export class NzBadgeComponent implements OnInit, AfterViewInit, OnChanges, OnDes
this.maxNumberArray = this.nzOverflowCount.toString().split('');
}
- constructor(private renderer: Renderer2, private elementRef: ElementRef, private contentObserver: ContentObserver) {
+ constructor(
+ private renderer: Renderer2,
+ private elementRef: ElementRef,
+ private contentObserver: ContentObserver,
+ private cdr: ChangeDetectorRef,
+ private ngZone: NgZone
+ ) {
renderer.addClass(elementRef.nativeElement, 'ant-badge');
}
@@ -98,6 +109,11 @@ export class NzBadgeComponent implements OnInit, AfterViewInit, OnChanges, OnDes
}
ngAfterViewInit(): void {
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
+ this.viewInit = true;
+ this.cdr.markForCheck();
+ });
+
this.contentObserver
.observe(this.contentElement)
.pipe(