I have my codes below. I wanted to set the parameters of the swiper slider using a script.
<swiper-container [options]="recentPostSliderOpts" class="discover-top-banner">
<swiper-slide *ngFor="let toplatestpost of toplatestposts">
<!-- Some Codes Here Cut Short -->
</swiper-slide>
</swiper-container>
Here's my code on typescript.
import { Swiper, SwiperOptions } from 'swiper/types';
recentPostSliderOpts: SwiperOptions = {
slidesPerView: 3,
}
The [options] is not getting triggered as per the guide on Ionic Framework - https://ionicframework.com/docs/angular/slides. It worked on Swiper 9, but not on Swiper 11. I have checked the SwiperJS Official Website documentation and can't find one. I have also also tried [config] without any luck.
Can anyone help on this?
To do that you will need to :
1 - create a directive for the swiper and use a template variable to keep the reference of the current swiper
2 - On the ts file, you will create the config you want, and put the swiper ref in a variable so you can listen to some events.
3 - Create the directive
4 - Then you have to add the SwiperDirective on your module imports array
5 - Add also schemas: [CUSTOM_ELEMENTS_SCHEMA] on your module to avoid some build errors
6 - Call the register function at only one place on your project. The app.module.ts is a good place
Now it should work. Good luck !