Skip to content

Commit d7b8323

Browse files
committed
fix: angular change detection errors
1 parent 67fcc0b commit d7b8323

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div *ngIf="orderedAttachments.length > 0" class="str-chat__attachment-list">
1+
<div
2+
*ngIf="isInited && orderedAttachments.length > 0"
3+
class="str-chat__attachment-list"
4+
>
25
<ng-container
36
*ngFor="let attachment of orderedAttachments; trackBy: trackByUrl"
47
>

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {
2+
AfterViewInit,
3+
ChangeDetectorRef,
24
Component,
35
EventEmitter,
46
HostBinding,
@@ -33,7 +35,7 @@ import { ThemeService } from '../theme.service';
3335
templateUrl: './attachment-list.component.html',
3436
styles: [],
3537
})
36-
export class AttachmentListComponent implements OnChanges {
38+
export class AttachmentListComponent implements OnChanges, AfterViewInit {
3739
/**
3840
* The id of the message the attachments belong to
3941
*/
@@ -56,6 +58,7 @@ export class AttachmentListComponent implements OnChanges {
5658
orderedAttachments: Attachment<DefaultStreamChatGenerics>[] = [];
5759
imagesToView: Attachment<DefaultStreamChatGenerics>[] = [];
5860
imagesToViewCurrentIndex = 0;
61+
isInited = false;
5962
themeVersion: '1' | '2';
6063
@ViewChild('modalContent', { static: true })
6164
private modalContent!: TemplateRef<void>;
@@ -70,11 +73,11 @@ export class AttachmentListComponent implements OnChanges {
7073
public readonly customTemplatesService: CustomTemplatesService,
7174
private channelService: ChannelService,
7275
private attachmentConfigurationService: AttachmentConfigurationService,
76+
private cdRef: ChangeDetectorRef,
7377
themeService: ThemeService
7478
) {
7579
this.themeVersion = themeService.themeVersion;
7680
}
77-
7881
ngOnChanges(changes: SimpleChanges): void {
7982
if (changes.attachments) {
8083
const images = this.attachments.filter(this.isImage);
@@ -95,6 +98,11 @@ export class AttachmentListComponent implements OnChanges {
9598
}
9699
}
97100

101+
ngAfterViewInit(): void {
102+
this.isInited = true;
103+
this.cdRef.detectChanges();
104+
}
105+
98106
trackByUrl(_: number, attachment: Attachment) {
99107
return (
100108
attachment.image_url ||

projects/stream-chat-angular/src/lib/message-list/message-list.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ export class MessageListComponent
144144
private ngZone: NgZone,
145145
private cdRef: ChangeDetectorRef
146146
) {
147+
this.usersTypingInChannel$ = this.channelService.usersTypingInChannel$;
148+
this.usersTypingInThread$ = this.channelService.usersTypingInThread$;
149+
}
150+
151+
ngOnInit(): void {
147152
this.subscriptions.push(
148153
this.channelService.activeChannel$.subscribe((channel) => {
149154
this.chatClientService.chatClient?.logger?.(
@@ -243,11 +248,6 @@ export class MessageListComponent
243248
}
244249
)
245250
);
246-
this.usersTypingInChannel$ = this.channelService.usersTypingInChannel$;
247-
this.usersTypingInThread$ = this.channelService.usersTypingInThread$;
248-
}
249-
250-
ngOnInit(): void {
251251
this.setMessages$();
252252
}
253253

0 commit comments

Comments
 (0)