我希望保存从API接收的数据并传递到Angular中的URL?
SERVICE.ts
readonly rootUrl = 'http://localhost:49940/';
constructor(private http: HttpClient) { }
getUserName(): Observable<any> {
return this.http.get<any>(this.rootUrl+'api/Account/GetUserClaims');
}
get(userName: string): Observable<any> {
let URL = `https://...?codSog=${userName}`;
return this.http.get<any>(URL);
}
您从api获取数据:
get(item: T): Observable<T> {
return this.http.get<T>('apiUrl');
}
保存:
save(){
this.get().subscribe(res => this.savedItem = res,
err => console.log(err),
_ => console.log('item saved'));
}
发送到下一个URL:
send(item: T): Observable<T> {
return this.http.post<T>('destinationUrl', item):
}