Reputation: 2304
I have this array called fieldlist which is coming from the below http.get request in angular 2 component. I have declared it like this .
fieldlist: string[] = [];
then I assigned its value using iteration of json resposne.
this.http.get(getform_endpoint,requestOptions).map((res:
Response) => res.json()).subscribe(
res => {
this.FormData = res.schema;
res.fields.forEach(element => {
this.fieldlist.push(element);
});
});
Now in another function like this
create_hidden_qp() {
let elementsnamevalue = this.fieldlist.join();
console.log("hello", this.fieldlist.join());
}
when I convert it to string using this lines it gives me blank "" response
but when I print it like this
console.log("hello", this.fieldlist);
I am able to see the perfect array like this.
hello[] 0 :"userroleid" 1: "ruletype" 2: "employeeid"
So what I am missing?
A) wrong declaration? b) wrong assigment? c) wrong access to array elements?
Upvotes: 0
Views: 382
Reputation: 71891
You should call the create_hidden_qp
after your request has finished:
this.http.get(getform_endpoint,requestOptions).map(r => r.json()).subscribe(res => {
this.FormData = res.schema;
res.fields.forEach(element => {
this.fieldlist.push(element);
});
this.create_hidden_qp();
});
Upvotes: 1