Skip to content

Instantly share code, notes, and snippets.

@jhades
Last active January 31, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhades/9ff79263e8c668476f6eedfda4ec2243 to your computer and use it in GitHub Desktop.
Save jhades/9ff79263e8c668476f6eedfda4ec2243 to your computer and use it in GitHub Desktop.
Angular Debugging "Expression has changed after it was checked" Error - Simple Explanation (and Fix)
@Component({
selector: 'course',
templateUrl: './course.component.html'
})
export class CourseComponent implements AfterViewInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
ngAfterViewInit() {
this.paginator.page
.pipe(
startWith(null),
tap(() => this.dataSource.loadLessons(...))
).subscribe();
}
}
export class LessonsDataSource implements DataSource<Lesson> {
private loadingSubject = new BehaviorSubject<boolean>(false);
public loading$ = this.loadingSubject.asObservable();
loadLessons(...) {
this.loadingSubject.next(true);
... load new data page from the backend
}
}
ngAfterViewInit() {
setTimeout(() => {
this.paginator.page
.pipe(
startWith(null),
tap(() => this.dataSource.loadLessons(...))
).subscribe();
});
}
import { startWith, tap, delay } from 'rxjs/operators';
ngAfterViewInit() {
this.paginator.page
.pipe(
startWith(null),
delay(0),
tap(() => this.dataSource.loadLessons(...))
).subscribe();
}
@Component({
selector: 'course',
templateUrl: './course.component.html'
})
export class CourseComponent implements AfterViewInit, OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
ngOnInit() {
// load the initial page
this.dataSource.loadLessons(...);
}
ngAfterViewInit() {
this.paginator.page
.pipe(
tap(() => this.dataSource.loadLessons(...))
).subscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment