Hi, I have a slider and I’d like to add the Swiper navigation arrows to it, but Ionic doesn’t seem to have that option. Swiper can initialize with arrows like this…
var swiper = new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
…but I’m not sure how to implement this in Ionic. Can someone give me some direction or tell me an elegant way to add this? Cheers.
The bigger issue is that you put a click directly on a div. If you do this, you need to include the tappable directive <div tappable (click)="foo">
or you can get performance issues., The code of @Shequeri had clicks only where they were expected. In theory, you can make anything clickable. In practice, I’ve tried not to surprise Ionic too often.
I implemented it. There was a little issue with the buttons not being in the proper location. They were behind the slides. Adding class="swiper-button-next" puts them into the right location, so you can use that to find out what else you need to add to the your class. Hope this helps anyone else with the same issue. Cheers.
Hi Shequeri, thank you for your suggestion and example. It has helped me make some progress here. The problem I am running into is that when the swiper-button is clicked, the swiper buttons move with the first slide and disappear. Here is my html markup:
What I noticed in Chrome Dev Tools is that when Ionic builds out the html, it places the buttons inside of the “swiper-wrapper” class element. When I manually move the button elements to be inside the parent element of “swiper-wrapper”, in this case, “swiper-container” (also automatically generated), I get the desired behaviour. That is, the buttons remain on page as you navigate through the slides. I can’t find any documentation that relates to this issue.
Basically I wrapped the whole thing in a div, and placed the buttons outside the <ion-slides> element. Not sure how the implementation suggested by Shequeri was supposed to work.
Good to know you managed to fix that. Practically that will be what I will suggest if I was to answer earlier. To be honest, I dont understand this part of your post “Not sure how the implementation suggested by Shequeri was supposed to work.”
@Shequeri, thanks for the code you provided but I cannot seem to get it to work for my project. I keep getting the error that Cannot read property of 'next' of undefined
I have used your following TypeScript code in my file like so:
import { Component, ViewChild } from ‘@angular/core’;
import { IonicPage, NavController, NavParams, Slides } from ‘ionic-angular’;
HTML code is fine and also the functions callback, but it just doesn’t recognise the declared ‘Slides’ property. Obviously I have declared it wrong but I cannot seem to figure it out.