I am working on a http request:
private getValues() {
this._watchlistElements.map(v =>
this.http.get('http://localhost/getValue/' + v.xid)
.subscribe(res => {
this._values.push(res.json());
}));
};
When the request is successful, I want to simplify it into one line of code:
this.vars.map((v,i) => v.push(this._values[i].value));
My query is how can I achieve something similar to .success: function(){}
in normal ajax with my current code?
Any assistance will be appreciated.
UPDATE
private getValues() {
this._watchlistElements.map(v =>
this.http.get('http://localhost/getValue/' + v.xid)
.subscribe(res => {
this._values.push(res.json());
})).then(console.log());
};
When attempting to use the then
method in Angular2, an error occurs. Can anyone advise me on which component I need to import for it to work properly?