问题
I'm getting to know hyperledger composer angular apps. This piece of code that yeoman generator produces puzzle me. The add
method executes return this.http.post
and it returns a response object, that is chained to a map
operator to convert to json output. But all references I could find to map
operator show that its argument must be specified, like an arrow function (v)=> {some instructions to perform on v here});
, or as an anonymous function (f(v){some instructions here})
;
I've seem the code below also in tutorials as a best practice to deal with response objects. Obviously map
operator also accepts a function and it sends the resulting response object to whom is chained to as the argument of the `map function. Could anyone provide links to where this mechanism is explained?
import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
public add(ns: string, asset: Type): Observable<Type> {
console.log('Entered DataService add');
console.log('Add ' + ns);
console.log('asset', asset);
return this.http.post(this.actionUrl + ns, asset)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response): any {
return res.json();
}
来源:https://stackoverflow.com/questions/50648218/why-is-argument-missing-in-chained-map-operator