55
66import { PlatformModule } from '@angular/cdk/platform' ;
77import {
8- AfterViewInit ,
98 ChangeDetectionStrategy ,
109 ChangeDetectorRef ,
1110 Component ,
@@ -16,6 +15,7 @@ import {
1615 Output ,
1716 ViewChild ,
1817 ViewEncapsulation ,
18+ afterRender ,
1919 numberAttribute
2020} from '@angular/core' ;
2121
@@ -33,11 +33,9 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'avatar';
3333 template : `
3434 @if (nzIcon && hasIcon) {
3535 <span nz-icon [nzType]="nzIcon"></span>
36- }
37- @if (nzSrc && hasSrc) {
36+ } @else if (nzSrc && hasSrc) {
3837 <img [src]="nzSrc" [attr.srcset]="nzSrcSet" [attr.alt]="nzAlt" (error)="imgError($event)" />
39- }
40- @if (nzText && hasText) {
38+ } @else if (nzText && hasText) {
4139 <span class="ant-avatar-string" #textEl>{{ nzText }}</span>
4240 }
4341 ` ,
@@ -59,7 +57,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'avatar';
5957 changeDetection : ChangeDetectionStrategy . OnPush ,
6058 encapsulation : ViewEncapsulation . None
6159} )
62- export class NzAvatarComponent implements OnChanges , AfterViewInit {
60+ export class NzAvatarComponent implements OnChanges {
6361 readonly _nzModuleName : NzConfigKey = NZ_CONFIG_MODULE_NAME ;
6462 @Input ( ) @WithConfig ( ) nzShape : NzShapeSCType = 'circle' ;
6563 @Input ( ) @WithConfig ( ) nzSize : NzSizeLDSType | number = 'default' ;
@@ -85,7 +83,9 @@ export class NzAvatarComponent implements OnChanges, AfterViewInit {
8583 public nzConfigService : NzConfigService ,
8684 private elementRef : ElementRef ,
8785 private cdr : ChangeDetectorRef
88- ) { }
86+ ) {
87+ afterRender ( ( ) => this . calcStringSize ( ) ) ;
88+ }
8989
9090 imgError ( $event : Event ) : void {
9191 this . nzError . emit ( $event ) ;
@@ -113,10 +113,6 @@ export class NzAvatarComponent implements OnChanges, AfterViewInit {
113113 this . calcStringSize ( ) ;
114114 }
115115
116- ngAfterViewInit ( ) : void {
117- this . calcStringSize ( ) ;
118- }
119-
120116 private calcStringSize ( ) : void {
121117 if ( ! this . hasText || ! this . textEl ) {
122118 return ;
0 commit comments