0
私はAngularを初めて使ったので、(クラス外の)関数に.map
を使ってWebService(REST)を呼び出しました。私は自動的にオブジェクト "応答"を取得します。しかし今、私のメソッド(と私のクラス)の中にある値をクラスの外にある関数にどのように送ることができますか?この値はWebServiceの応答とは関係ありません。「クラス」から「関数」に別の値を渡す方法
@Injectable()
export class MyClass {
getEvents(myValue: string): Observable<CalendarEvent[]> {
this.http
.get("url of webservice")
.map(mapEvents) <- how can I put "myValue" here
.catch(handleError);
}
}
function mapEvents(response: Response): CalendarEvent[] {
return response.json().map(toEvent);
}
function toEvent(event: any): CalendarEvent {
const s_event = <CalendarEvent>(
{
value : myValue; <- to get "myValue" here?
});
return s_event;
}
あなたがすることはできませんを使用し、それはそこに利用できません。明示的に渡す必要があります(例: '.map(event => mapEvents(event、myValue))'です。 – jonrsharpe
質問が不明です – Ced