我正在嘗試提出我的第一個HTTP POST請求。我的GET請求工作正常(在同一服務(wù)中),但是當(dāng)我嘗試發(fā)出POST請求時卻出現(xiàn)了錯誤錯誤TypeError:無法讀取ApiService.push ../ src / app / services / api.service.ts.ApiService.getTracsStartEvents(api.service.ts:57)上未定義的屬性“ post”我在同一文件中以與使用GET請求相同的方式使用它。我不明白為什么POST請求無法正常工作。我必須在語法上犯一些錯誤。誰能指出我正確的方向?這是我稱為post函數(shù)的位置(這是從另一個獲取位置更新的服務(wù)中獲得的):import { Injectable } from '@angular/core';import { ApiService } from './api.service';import { GeoJson } from '../shared/geo-json';@Injectable({ providedIn: 'root'})export class PositionUpdateService { positionUpdate: GeoJson; constructor(private apiService: ApiService, ) { this.positionUpdate = new GeoJson( 'Feature', {type: 'Point', coordinates: [-121.0, 37.5, 1000]} ); //console.log('posUpdate: this.positionUpdate: ', this.positionUpdate ); } getMissionStartEvents( devices ) { console.log('posUpdate svc, getMissionStartevents, imeis: ', devices); const events = this.apiService.getTracsStartEvents( devices ); console.log(events); }}一切從我的地方開始HomeComponent:export class HomeComponent implements OnInit, OnChanges { constructor(public appSettingsService: AppSettingsService, public layerControlDialogComponent: MatDialog, private devicesToTrackService: DevicesToTrackService, private positionUpdateService: PositionUpdateService, private httpClient: HttpClient) { } startTracking(devices) { console.log('going to start tracking ', devices); this.positionUpdateService.getMissionStartEvents(devices) }
Angular http發(fā)布錯誤:無法讀取未定義的屬性“ post”
BIG陽
2021-04-09 06:30:38