I have an implementation that requires querying a selector within the ion-slides and change their colours . This works as expected on the first page, but did not work on subsequent pages .
I noticed though that when sliding to another page from the page that seems not to work, it will then show at the point of transition.
This is how I am handling this
let arrs = document.querySelector('#v1')
arrs.scrollIntoView();
arrs.classList.add('current-verse')
arrs.setAttribute('color','primary')
it scrolls to view, but the attribute and the class are not instantaneously applied on follow-up pages .
I tried to trigger update() but still did not work
Property binding. You should virtually never be interacting directly with the DOM in an Angular application, and I can see no reason for doing so here.
Thank you @rapropos, What I am working on is a series of audio files, whose text are already on the page. I only want the current track highlighted , and these tracks are dynamic.
I implemented this on a list without issues, but it just doesn’t work work on slides follow-up pages.
How do I use a property binding only on a selected element. sorry if this look stupid, I just can’t think straight right now.
Well, there are two major ways: one would be to put a boolean selected property on each backing item. The other is to keep the selection separately as a controller property, like so:
<ion-slides>
<ion-slide *ngFor="let fruit of fruits; let i = index" [class.selected]="selix === i">
<div [innerText]="fruit"></div>
<ion-button (click)="selix = i">select this fruit</ion-button>
</ion-slide>
</ion-slides>
Thank you once more, but it’s not working yet; The item selection is automatic and not at a button click. This is how I have used your suggestion
<ion-slides [options]="sliderConfig" (ionSlideDidChange)="slideChanged()">
<ion-slide *ngFor="let p of pages" >
<div >
<div class="ion-text-center " >
<ion-text class="ion-text-center v_{{verse.verse}}" *ngFor="let verse of range let even = even let i = index" id=pagev{{verse.verse}} [class.focus]="scrollTo == verse.verse" [class.selected]="selix === verse.verse" >
<span >{{verse.content}}
</span>
<img class="avatar" style="max-height:18px" src="/assets/v2/{{verse.verse}}.png">
</ion-text>
</div>
</div>
</ion-slide>
</ion-slides>
Then in my controller code behind
public selix = null;
Then the function that goes to appropriate page in the slide and meant to highlight current verse
slideToRightPage(verse){
verse = parseInt(verse)
let index = this.range.findIndex(x=>x.verse==verse)
if(index == -1){
if(verse>this.range[this.range.length-1].verse){
this.slides.nativeElement.slideNext()
}
if(verse<this.range[0].verse){
this.slides.nativeElement.slidePrev()
}
setTimeout(()=>{
this.slideToRightPage(verse)
},1000)
}else {
let arrs = document.querySelector('.v_'+verse)
this.resetVerseColour()
this.selix=verse;
arrs.scrollIntoView();
// arrs.classList.add('current-verse')
//arrs.setAttribute('color','primary') // this was working but only on the first page
})
}
}