Я пытаюсь создать POST-запрос в Angular v7 из службы.Мой класс обслуживания уже содержит некоторые запросы get, которые извлекают данные из моего API.Теперь мне нужно опубликовать данные, и я не могу понять формат / синтаксис (все еще плохо знакомый с angular).
В VSCode я вижу, что это говорит Property 'subscribe' does not exist on type
'void'.
Вот служба
Shipment.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, tap, map } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { Ziptastic } from '../interfaces/ziptastic';
import { ReturnShipment } from '../interfaces/return-shipment';
import { HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
@Injectable({
providedIn: 'root'
})
export class ShipmentService {
private shipmentCreation = 'api/ReturnShipmentQueues';
constructor(private http: HttpClient) { }
}
submitShipment(rShip: ReturnShipment) {
this.http.post(this.shipmentCreation, rShip, httpOptions)
.subscribe(
data => {console.log('AllthePost' + JSON.stringify(data));},
err => {console.log("error occurred");}
);
}
private handleError(handleError: any): import("rxjs").OperatorFunction<any[], any> {
throw new Error("Method not implemented.");
}
}