Angular - przesłanie obiektu wraz z parametrami GET

0

Witajcie,
Mam zapewne błahe pytanie dla wyjadaczy angulara :)
Potrzebuje przesłać przez httpClient metodą GET wraz z parametrami obiekt. Jak mogę to zrobić? Gdybym wysyłał sam obiekt to pół biedy ale tu właśnie są parametry + obiekt.
Próbowałem dodać do httparams append("nazwaParametru", <any>obiekt) ale w kontrolerze API dostawałem puste parametry.
Przepraszam za taką składnie ale wiadomość pisana jest z telefonu.
Frontend angular 8.
Backend .net core 3.1
Pozdrawiam i z góry dziękuję

0

Jako że nie podałeś swojego kodu, to wklejam przykład mojego.

GET w kontrolerze .NET Core:

/// <summary>
        /// GET: api/game/join
        /// </summary>
        /// <returns>Game status model.</returns>
        [HttpGet("join")]
        [Authorize(AuthenticationSchemes = "Bearer", Roles = "Admin, User")]
        public IActionResult JoinGame(int id)
        {
            List<GameStateModel> list = _memoryAccess.GetGameList();
            GameStateModel model = _memoryAccess.GetGameList().Where(g => g.GameId == id).FirstOrDefault();

            if (model == null)
            {
                return new ObjectResult("Game does not exists.") { StatusCode = 409 };
            }

            return Json(model);
        }

I żądanie HTTP z Angular:

const url: string = environment.apiUrl + 'api/game/join?id=' + id;
this.httpService.getData(url).subscribe((game: GameState) => {
      if (game) { //do sth with game object }
}

gdzie w httpService getData(url) to:

public getData(url: string): Observable<any> {
    this.spinner.show();
    this.result = this.requestResult(url);
    this.spinner.hide();
    return this.result;
  }
private requestResult(url: string): Observable<any> {
    return this.http.get<any>(url);
  }
0

Możesz z obiektu zrobić JSON i to przepchnąć w query stringu. Rada: nie rób tak.

1 użytkowników online, w tym zalogowanych: 0, gości: 1