Last active
January 31, 2018 08:13
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngAfterViewInit() { | |
setTimeout(() => { | |
this.paginator.page | |
.pipe( | |
startWith(null), | |
tap(() => this.dataSource.loadLessons(...)) | |
).subscribe(); | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { startWith, tap, delay } from 'rxjs/operators'; | |
ngAfterViewInit() { | |
this.paginator.page | |
.pipe( | |
startWith(null), | |
delay(0), | |
tap(() => this.dataSource.loadLessons(...)) | |
).subscribe(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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