Skip to content

Commit

Permalink
fix(FileUpload): protect against cdr being called after it's destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincharity committed Feb 19, 2019
1 parent 9ade135 commit 0990b38
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions terminus-ui/file-upload/src/file-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ export class TsFileUploadComponent extends TsReactiveFormBaseComponent implement
*/
public updateInnerValue = (value: string): void => {
this.value = value;
this.changeDetectorRef.detectChanges();

// NOTE: This `if` is to avoid: `Error: ViewDestroyedError: Attempt to use a destroyed view: detectChanges`
// istanbul ignore else
if (!this.changeDetectorRef['destroyed']) {
this.changeDetectorRef.detectChanges();
}
}


Expand All @@ -501,7 +506,11 @@ export class TsFileUploadComponent extends TsReactiveFormBaseComponent implement
this.formControl.valueChanges.pipe(
untilComponentDestroyed(this),
).subscribe(() => {
this.changeDetectorRef.detectChanges();
// NOTE: This `if` is to avoid: `Error: ViewDestroyedError: Attempt to use a destroyed view: detectChanges`
// istanbul ignore else
if (!this.changeDetectorRef['destroyed']) {
this.changeDetectorRef.detectChanges();
}
});
}
}
Expand Down

0 comments on commit 0990b38

Please sign in to comment.