Skip to content

Commit

Permalink
[AAE-17103] Add ChangeDetectorRef
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktord2000 committed Oct 23, 2023
1 parent 22fda81 commit 2326253
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ describe('IconCellComponent', () => {
});

describe('UI', () => {
it('should render icon element in case of non-empty string', () => {
it('should render icon element in case of non-empty string (icon name validation NOT included)', () => {
renderAndCheckResult('group', true, 'group');
renderAndCheckResult('groupe', true, 'groupe');
renderAndCheckResult('0', true, '0');
renderAndCheckResult('false', true, 'false');
});

describe('should NOT render icon element in case of', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewEncapsulation } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component';
import { takeUntil } from 'rxjs/operators';
Expand All @@ -37,14 +37,19 @@ import { takeUntil } from 'rxjs/operators';
export class IconCellComponent extends DataTableCellComponent implements OnInit {
protected icon: string = '';

constructor(private changeDetectorRef: ChangeDetectorRef) {
super();
}

ngOnInit(): void {
super.ngOnInit();
this.value$.pipe(takeUntil(this.onDestroy$)).subscribe((value) => {
this.icon = this.validateIconValue(value) ? value : '';
this.changeDetectorRef.detectChanges();
});
super.ngOnInit();
}

private validateIconValue(value: any): boolean {
return typeof value === 'string';
};
}
}

0 comments on commit 2326253

Please sign in to comment.