I'm using this code:
private ARRAYDATA: any[];
constructor(private http: Http) {
this.getCards('data.json');
}
getCards(url)
{
this.http.get(url)
.map(response => response.json())
.subscribe(
function(response) {
console.log(response); //show object
},
function(error) { console.log("Error happened" + error)},
function() { console.log("the subscription is completed")}
);
}
This code works, now I can not understand how to pass an object RESPONSE to a variable ARRAYDATA
; Help me please!
This code does not work:
getCards(url)
{
this.http.get(url)
.map(response => response.json())
.subscribe(
function(response) {
console.log(response); //show object
this.arraydata = response;
},
function(error) { console.log("Error happened" + error)},
function() { console.log("the subscription is completed")}
);
console.log(this.arraydata)// show undefind
}
I need to use a variable ARRAYDATA outside the function. right here
constructor(private http: Http) {
this.getCards('data.json');
console.log(this.ARRAYDATA);
}