第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular http發(fā)布錯誤:無法讀取未定義的屬性“ post”

Angular http發(fā)布錯誤:無法讀取未定義的屬性“ post”

BIG陽 2021-04-09 06:30:38
我正在嘗試提出我的第一個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)  }
查看完整描述

2 回答

?
拉莫斯之舞

TA貢獻1820條經(jīng)驗 獲得超10個贊

請確保將您的注釋ApiService為Injectable():


@Injectable({

  providedIn: 'root',

})

export class ApiService {

然后,不要創(chuàng)建ApiService自己,這就是依賴注入的目的。它將自動創(chuàng)建ApiService具有其依賴項的實例(HttpClient在這種情況下):


export class PositionUpdateService {

  // The dependency injection will automatically instantiate ApiService

  constructor(private apiService: ApiService) {

   }


  // ...

}


查看完整回答
反對 回復(fù) 2021-04-15
  • 2 回答
  • 0 關(guān)注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號