0
votes

core.js:4352 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'swiper-slide swiper-slide-active '. Current value: 'swiper-slide '.

this is my code :

        <swiper [slidesPerView]="1" [spaceBetween]="50" [navigation]="true" [pagination]="{ clickable: true }" [scrollbar]="{ draggable: true }">

            <ng-template swiperSlide *ngFor="let advertiser of staticAdvertisers; let indice=index">

                <a [href]="[advertiser?.link]" target="_blank">

                    <div class="item-container">
                    
                        <div class="advert-cover display-feed-player">
                
                                                
                            
                        </div>
                        
                    </div>   

                </a>
        
            </ng-template>

        </swiper>

    </div>    

and this the .ts

import SwiperCore, { Navigation, Swiper } from "swiper/core";

SwiperCore.use([Navigation]);

@UntilDestroy()

@Component({ selector: 'app-social', templateUrl: './social.component.html', styleUrls: ['./social.component.scss'], animations: [ trigger('fadeIn', [ transition(':enter', [ style({ opacity: '0' }), animate('0.8s ease', style({ opacity: '1' })), ]), ]), ], })

export class SocialComponent implements OnInit, AfterViewInit, OnDestroy {

public getUsernameOrId = getUsernameOrId;
private user;
public currentUser;
public playerUrl = environment.playerUrl;


/* styleTest */
public desktop: any = screen.width >= 1200;
public laptop: any = screen.width >= 1024 && screen.width < 1200;
public tablet: any = screen.width >= 768 && screen.width < 1024;
public mobile: any = screen.width === 320 && screen.width < 768;
/* styleTest */

thanks in advance .

2
please provide the code of the whole component.tsenno.void

2 Answers

0
votes
the "ExpressionChangedAfterItHasBeenCheckedError" telling that you've changed something after initialization.

based on your provided code, it seems that you are removing "swiper-slider" class from element, or replacing it with another one...

"swiper-slide" class must be on ever slide element, always !

here's default implementation of swiper

<div class="swiper-container">
    <!-- Additional required wrapper -->
    <div class="swiper-wrapper">
        <!-- Slides -->
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
        ...
    </div>
    <!-- If we need pagination -->
    <div class="swiper-pagination"></div>

    <!-- If we need navigation buttons -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- If we need scrollbar -->
    <div class="swiper-scrollbar"></div>
</div>
0
votes

I had the same problem in the past days and somehow figured out after awhile that *ngIfs and *ngFors inside swiperSlides broke it because of the way swiper is initialized. This way I found a recent issue on Swiper GitHub: https://github.com/nolimits4web/swiper/issues/4123

And it turns out this behaviour was fixed in yesterday's update (6.4.9): https://github.com/nolimits4web/swiper/blob/master/CHANGELOG.md

When I updated the Swiper version from 6.4.8 to 6.4.10, there was no more error and slides now work as expected. It seems quite some effort has lately been put into Swiper and Angular working together so there have been quite many updates recently which might fix your issue as well.