Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ describe('IgxHighlight', () => {

expect(() => component.highlight.activateIfNecessary()).not.toThrowError();
});

it('Should not throw error when destroyed before ngAfterViewInit completes', () => {
// Create the component but do NOT call detectChanges()
// This simulates the directive being destroyed before ngAfterViewInit is called
const fix = TestBed.createComponent(HighlightLoremIpsumComponent);

// Destroy the component without initializing it
expect(() => fix.destroy()).not.toThrowError();
});
});

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
public clearHighlight(): void {
this.clearChildElements(false);

this._lastSearchInfo.searchText = '';
this._lastSearchInfo.matchCount = 0;
if (this._lastSearchInfo) {
this._lastSearchInfo.searchText = '';
this._lastSearchInfo.matchCount = 0;
}
}

/**
Expand Down
Loading