I have an angular component where the idea is it has one container div, with two child box divs. Both child divs inherit the full width of the parent. But only one child is visible on-screen at once. When the "next()" method is called, the children divs slide across using the "left" property, to switch between which is visible.
Here is some simplified code for how I'm doing it:
<div class="add-partner-container">
<div class="box" [style.left]="sliderIndex === 0 ? '0' : '-100%'">
<p>First Box</p>
</div>
<div class="box" [style.left]="sliderIndex === 1 ? '0' : '100%'">
<p>Second Box</p>
</div>
</div>
.add-partner-container {
width: 100%;
height: 11rem;
display: flex;
flex-direction: row;
overflow: hidden;
position: relative;
}
.box {
width: 100%;
position: absolute;
transition: left 0.5s ease-in-out;
display: flex;
flex-direction: column;
align-items: center;
overflow-y: hidden;
}
public sliderIndex: number = 0;
public next() {
this.sliderIndex = (this.sliderIndex + 1) % 2;
}
I have this problem:
When I first open the angular component in the browser, it initially correctly shows the first box, as it should. But it suddenly switches to showing the second box, which it should not show until the "next()" method is called, which it has not been yet.
The next() method is not accidentally being called. The sliderIndex field is not being modified by any other part of the code.
I've confirmed all of this.