Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: NG0100: ExpressionChangedAfterItHasBeenCheckedError #20

Open
AlexanderBelkin opened this issue Jul 22, 2021 · 4 comments
Open

Bug: NG0100: ExpressionChangedAfterItHasBeenCheckedError #20

AlexanderBelkin opened this issue Jul 22, 2021 · 4 comments

Comments

@AlexanderBelkin
Copy link

I used the default example and when I removed *ngFor.
as :

<mat-carousel
....params
>
  <mat-carousel-slide > first slide  </mat-carousel-slide>

  <mat-carousel-slide> second slide  </mat-carousel-slide>
</mat-carousel>

I got an error :

ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '[object Object]'.. Find more at https://angular.io/errors/NG0100

my goal was to make a certain number of slides without using a loop.

Can I solve this error locally?

Thank for your help

@tagazok
Copy link

tagazok commented Aug 19, 2021

Same error here while creating slides directly from HTML and not from a for loop.

Complete trace below

core.js:6479 ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '[object Object]'.. Find more at https://angular.io/errors/NG0100
    at throwErrorIfNoChangesMode (core.js:6776)
    at bindingUpdated (core.js:12988)
    at Module.ɵɵproperty (core.js:14783)
    at MatCarouselComponent_li_4_Template (ngbmodule-material-carousel.js:56)
    at executeTemplate (core.js:9598)
    at refreshView (core.js:9464)
    at refreshEmbeddedViews (core.js:10589)
    at refreshView (core.js:9488)
    at refreshComponent (core.js:10635)
    at refreshChildComponents (core.js:9261)

@mac1253
Copy link

mac1253 commented Sep 30, 2021

I too had the issue and couldnt resolve this. Any updates on this?
EDIT: I wasn't able to get it working right from the docs but I hacked the demo apart but had to fit an image tag within the slide tag and just fit it to what it would normally be.

@Babelfish112
Copy link

Any updates? Same error here - it's unfortunately preventing me from using this module at all.

@notman
Copy link

notman commented Aug 22, 2022

This may be a result of implementation. Without seeing all the code, it's difficult to know, but based on the error messaging, it appears you are setting the an array, for the ngFor, but not initially defining that array.
For example, if you are doing the following in your component:

public slides: Slide[];

public ngOnInit():{
 loadSlides().subscribe((loadedSlides: Slide[]) => this.slides = loadedSlides);
} 

You should instead do this:

public slides: Slide[] = [];

public ngOnInit():{
 loadSlides().subscribe((loadedSlides: Slide[]) => this.slides = loadedSlides); 
//or
 loadSlides().subscribe((loadedSlides: Slide[]) => this.slides = this.slides.concat(loadedSlides)); 
} 

Or add a changeDetectorRef and set 'detectChanges' in your ngOnInit. This is another way to get angular to process the current value, before you change it to an array. The better practice would be to always initialize your properties though.

Again, this is all based on assumptions, without seeing the actual implementation. These are solutions that typically resolve that 'expression changed' error. We use async pipes, which offer a better way of handling this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants