I want to execute a "each" function in jQuery, after initializing my carousel. But, on ngOnInit() function, I have an asynchonous task with http.get to get data I need to initialize the carousel.
My code :
ngOnInit() {
this.list();
$('.carousel').carousel();
}
list(): void {
this.http.get(`http://localhost:8082/api/list`)
.subscribe(response => {
this.c= response.json().data;
}, error => {
this.error = error;
})
}
ngAfterViewInit() {
// Your jQuery code goes here
$('.carousel .item').each(function () {
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
for (var i = 0; i < 2; i++) {
next = next.next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
}
});
}
The each function is not execute...