Can't believe I am asking this, but I did not find an answer to this problem. As you can guess I am fairly new to Angular.
How can I change public slideNumber = 1
dynamically within a class?
export class TestimonialComponent {
public slideNumber = 1;
Carousel() {
setInterval(function () {
this.slideNumber = 9;
}, 1000);
}
ngOnInit(): void {
this.Carousel();
this.slideNumber = 3;
}
}
from my understanding ngOnInit shares slideNumber with the class, but the Carousel function declares its own slideNumber.
My question is why does this happen and how can I dynamically change the first declared variable in the class? (public slideNumber = 1
)
Clarification
- ngOnInit changes the
public slideNumber = 1
to 3 - Carousel function creates it's own property
this.slideNumber = 9
This means that public slideNumber = 1
is now 3 and Carousel is not able to interact with public slideNumber = 1