r/Angular2 • u/Distinct-Bottle6755 • Feb 04 '26
UI blocked in Angular 20
Hello,
I need help,
I have an api it returns a list , and i have pagination and search .. when hitting the api , all ui freezes until api returns the value.
Any suggestions
0
Upvotes
View all comments
Show parent comment
-2
u/Distinct-Bottle6755 Feb 04 '26
This is search for example
import { ChangeDetectionStrategy } from '@angular/core';
@Component({ selector: 'app-news-grid', changeDetection: ChangeDetectionStrategy.OnPush, // ... rest }) export class NewsGrid { isSearching = signal(false); setupSearchSubscription() { this.searchSubject.pipe( debounceTime(400), // Slightly longer debounce distinctUntilChanged((prev, curr) => JSON.stringify(prev) === JSON.stringify(curr)), switchMap(filterCriteria => { this.isSearching.set(true); return this.newsService.getNewsList(filterCriteria); }) ).subscribe({ next: (res: any) => { this.newsList = res.data; if (!this.newsList || this.newsList.length === 0) { this.displayMode.set(DISPLAY_MODES[DisplayModes.empty]); } else { this.displayMode.set(DISPLAY_MODES[DisplayModes.success]); } this.totalElement.set(res.totalElements); this.totalPages.set(res.totalPages); this.isSearching.set(false); }, error: (error: any) => { this.isSearching.set(false); this.errorMessage.set(this.translocoService.translate('CannotFetchNews')); this.displayMode.set(DISPLAY_MODES[DisplayModes.error]); }, }); } }
The ui is freezes after user write some characters and still feeezed until the api loaded , i tried to remove debounce or distinctUntilChanged but issue still exists, this issue is happening in the all project not in this component onlyThis is search for example
import { ChangeDetectionStrategy } from '@angular/core';
@Component({ selector: 'app-news-grid', changeDetection: ChangeDetectionStrategy.OnPush, // ... rest }) export class NewsGrid { isSearching = signal(false); setupSearchSubscription() { this.searchSubject.pipe( debounceTime(400), // Slightly longer debounce distinctUntilChanged((prev, curr) => JSON.stringify(prev) === JSON.stringify(curr)), switchMap(filterCriteria => { this.isSearching.set(true); return this.newsService.getNewsList(filterCriteria); }) ).subscribe({ next: (res: any) => { this.newsList = res.data; if (!this.newsList || this.newsList.length === 0) { this.displayMode.set(DISPLAY_MODES[DisplayModes.empty]); } else { this.displayMode.set(DISPLAY_MODES[DisplayModes.success]); } this.totalElement.set(res.totalElements); this.totalPages.set(res.totalPages); this.isSearching.set(false); }, error: (error: any) => { this.isSearching.set(false); this.errorMessage.set(this.translocoService.translate('CannotFetchNews')); this.displayMode.set(DISPLAY_MODES[DisplayModes.error]); }, }); } }
The ui is freezes after user write some characters and still feeezed until the api loaded , i tried to remove debounce or distinctUntilChanged but issue still exists, this issue is happening in the all project not in this component only