Hey guys I'm new to angular2
tried several ways to achieve this kind of functionality (look at jsfiddle).
What I need is on click it add active class to next element and removes from current element same vice-versa for Prev btn.so that next element will be shown and prev one will be hided. add/remove class or add remove style could work for me..or anything else that can achieve this kind of thing
I have just achieved it with jQuery.
But I just want to implement it with Angular2, anything can work for me
html:
<ul>
<li class="active">item1</li>
<li>item2</li>
<li>item3</li>
</ul>
<button class="prev">prev</button> <button class="next">Next</button>
jQuery:
$('.next').click( function(){
$('.active').next().addClass('active').prev().removeClass('active')
})
$('.prev').click( function(){
$('.active').prev().addClass('active').next().removeClass('active')
})
https://jsfiddle.net/svgmc125/
Edit:
code updated using help of @pixelbits help
now HTML will be
<li>
<my-component></my-component>
</li>
<li>
<my-component-1></my-component-1>
</li>
<li [class]="slides[selectedIndex] == slide ? 'active': ''"
*ngFor="let slide of slides">
<img src="../../assets/images/onboarding/slides/{{slide}}.png" alt="">
</li>
<li>
<my-component-2></my-component-2>
</li>
<li>
<my-component-3></my-component-3>
</li>
ts:
export class SlidesComponent{
slides: any[];
selectedIndex: number;
constructor() {
this.selectedIndex = 0;
this.slides = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
}
next() {
++this.selectedIndex;
}
previous() {
--this.selectedIndex;
}
}
its all working fine for looped <li> but still have issue with remaining <li>