I am new to angular. I am working with trello API. I have an array in which I have some list ID's. I want to make HTTP get call for list id array length times. in the example I have two ID's so the HTTP call should be done for two times. I get cards (array of objects) as response in each http request. I want to concat or push response in one array. as bellow example I push data to the taskArray but it does not store anything.
for first call it return - data (3) [{…}, {…}, {…}]
for first call it return - data (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
expected output after concatenation is - data (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
current output is - data []
//component.ts
public listArr = ['5c78bebad10c40163a4f8fc6', '5c7cf40cb8f22b26862602aa'];
public taskArr = [];
ngOnInit() {
for (var i = 0; i < this.listArr.length; i++) {
let apiUrl = 'lists/' + this.listArr[i] + '/cards?key=12345688888888&token=b65ss88rhsnjj78925556dkjsagfsv';
this._service.trelloCall(apiUrl)
.subscribe(
data => {
this.taskArr.push(data)
}
}
console.log('taskArr', this.taskArr)
}
}
//service.ts
public trelloUrl = 'https://api.trello.com/1/';
trelloCall(apiUrl) {
return this.http.get < any > (this.trelloUrl + apiUrl)
.pipe(
map(data => {
return data;
}),
catchError(error => {
return throwError('Something went wrong!')
})
)
}
this.taskArr = this.taskArr.concat(data);instead? And also, do the console log inside here:data => {this.taskArr.push(data)}because of async