5
5
6
6
import { PlatformModule } from '@angular/cdk/platform' ;
7
7
import {
8
- AfterViewInit ,
9
8
ChangeDetectionStrategy ,
10
9
ChangeDetectorRef ,
11
10
Component ,
@@ -16,6 +15,7 @@ import {
16
15
Output ,
17
16
ViewChild ,
18
17
ViewEncapsulation ,
18
+ afterRender ,
19
19
numberAttribute
20
20
} from '@angular/core' ;
21
21
@@ -33,11 +33,9 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'avatar';
33
33
template : `
34
34
@if (nzIcon && hasIcon) {
35
35
<span nz-icon [nzType]="nzIcon"></span>
36
- }
37
- @if (nzSrc && hasSrc) {
36
+ } @else if (nzSrc && hasSrc) {
38
37
<img [src]="nzSrc" [attr.srcset]="nzSrcSet" [attr.alt]="nzAlt" (error)="imgError($event)" />
39
- }
40
- @if (nzText && hasText) {
38
+ } @else if (nzText && hasText) {
41
39
<span class="ant-avatar-string" #textEl>{{ nzText }}</span>
42
40
}
43
41
` ,
@@ -59,7 +57,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'avatar';
59
57
changeDetection : ChangeDetectionStrategy . OnPush ,
60
58
encapsulation : ViewEncapsulation . None
61
59
} )
62
- export class NzAvatarComponent implements OnChanges , AfterViewInit {
60
+ export class NzAvatarComponent implements OnChanges {
63
61
readonly _nzModuleName : NzConfigKey = NZ_CONFIG_MODULE_NAME ;
64
62
@Input ( ) @WithConfig ( ) nzShape : NzShapeSCType = 'circle' ;
65
63
@Input ( ) @WithConfig ( ) nzSize : NzSizeLDSType | number = 'default' ;
@@ -85,7 +83,9 @@ export class NzAvatarComponent implements OnChanges, AfterViewInit {
85
83
public nzConfigService : NzConfigService ,
86
84
private elementRef : ElementRef ,
87
85
private cdr : ChangeDetectorRef
88
- ) { }
86
+ ) {
87
+ afterRender ( ( ) => this . calcStringSize ( ) ) ;
88
+ }
89
89
90
90
imgError ( $event : Event ) : void {
91
91
this . nzError . emit ( $event ) ;
@@ -113,10 +113,6 @@ export class NzAvatarComponent implements OnChanges, AfterViewInit {
113
113
this . calcStringSize ( ) ;
114
114
}
115
115
116
- ngAfterViewInit ( ) : void {
117
- this . calcStringSize ( ) ;
118
- }
119
-
120
116
private calcStringSize ( ) : void {
121
117
if ( ! this . hasText || ! this . textEl ) {
122
118
return ;
0 commit comments