i am try to build Angular project , i have tow different API news sources . l want to display the tow API news as randomly like :
- element news 1
- element news 2
- element news 1
- element news 2
But what i have in my code below is
- element news 1 loop
- element news 2 loop
news.ts
news_one_array:any
news_tow_array:any
ngOnInit() {
this.news_one()
this.news_tow()
}
async news_one() {
this.http.get("/nodes/25/iq/0/20/xlarge")
.pipe(timeout(5000),
catchError(err => {
console.log(err)
return Observable.throw("Timeout has occurred");
})).subscribe(data => {
this.news_one_array = data
})
}
async news_tow() {
this.http.get("/nodes/25/iq/0/21/xlarge")
.pipe(timeout(5000),
catchError(err => {
console.log(err)
return Observable.throw("Timeout has occurred");
})).subscribe(data => {
this.news_tow_array = data
})
}
HTML :
// *ngfor news 1
<div *ngFor="let items of news_one_array; let i=index">
<p>{{items.title}}</p>
</div>
// *ngfor news 2
<div *ngFor="let items of news_tow_array; let i=index">
<p>{{items.title}}</p>
</div>
output :