Skip to content

Commit 0da20cb

Browse files
authored
fix(button): icon button asynchronous content is not refreshed (#117)
Co-authored-by: tuan <>
1 parent bae2a00 commit 0da20cb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

devui/button/button.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import {
2-
ChangeDetectionStrategy, Component, ElementRef,
3-
EventEmitter, HostListener, Input, Output, TemplateRef, ViewChild
2+
AfterContentChecked,
3+
ChangeDetectionStrategy,
4+
ChangeDetectorRef,
5+
Component,
6+
ElementRef,
7+
EventEmitter,
8+
HostListener,
9+
Input,
10+
Output,
11+
TemplateRef,
12+
ViewChild,
413
} from '@angular/core';
514
export type IButtonType = 'button' | 'submit' | 'reset';
615
export type IButtonStyle = 'common' | 'primary' | 'text' | 'text-dark' | 'danger';
@@ -14,7 +23,7 @@ export type IButtonSize = 'lg' | 'md' | 'sm' | 'xs';
1423
changeDetection: ChangeDetectionStrategy.OnPush,
1524
preserveWhitespaces: false,
1625
})
17-
export class ButtonComponent {
26+
export class ButtonComponent implements AfterContentChecked {
1827
@Input() id: string;
1928
@Input() type: IButtonType = 'button';
2029
@Input() bsStyle: IButtonStyle = 'primary';
@@ -38,8 +47,7 @@ export class ButtonComponent {
3847
}
3948
}
4049

41-
constructor() {
42-
}
50+
constructor(private cd: ChangeDetectorRef) {}
4351

4452
// 新增click事件,解决直接在host上使用click,在disabled状态下还能触发事件
4553
onClick(event) {
@@ -48,6 +56,10 @@ export class ButtonComponent {
4856
}
4957
}
5058

59+
ngAfterContentChecked(): void {
60+
this.cd.detectChanges();
61+
}
62+
5163
hasContent() {
5264
return !!this.buttonContent && this.buttonContent.nativeElement && this.buttonContent.nativeElement.innerHTML.trim();
5365
}

0 commit comments

Comments
 (0)