I’m trying to load with constructor names for dynamically generated buttons from list public names: any = [];
by number this.nmb
, generated this way:
name.ts
NamePage
:
name() {
this.names = [];
for (var i = 0; i <= this.nmb; i++) {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let postParams = '&user=' + this.user + '&num=' + i;
this.http.post(this.phpPath + "select.php", (postParams), options)
.subscribe(data => {
this.names.push(data.text().trim());
}, error => {
console.log(error);
});
}
}
with backend select.php
:
then by num
from btnsArray
which is equal to this.nmb
in name.html
, but each time list created differently, with one load public names: any = [];
order proper:
Sally
John
Said
Maria
without certain sequence, but randomly, with another constructor load, loading order wrong:
John
Sally
Said
Maria
So It makes the correct loading of the NamePage
content (click)="fnc(nmb)
by the order from MySql
, but sometimes not through the correct name assigned to the button {{bandNames[nmb]}}
.
Seems like something wrong with loading this.names.push(data.text().trim());
but I’m not sure what exactly.
Advice would be helpful