簡體   English   中英

使用 Angular 中可觀察的數據制作 http 帖子

[英]Make http post with data from observable in Angular

我想使用來自我的registerStore服務中的 observable 的數據將它們發送到我的 http 發布請求的正文中。 我該怎么做?

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '@env/environment';
import { RegisterStore } from './register.store';

@Injectable({ providedIn: 'root' })
export class RegisterService {
  constructor(
    private httpClient: HttpClient,
    private registerStore: RegisterStore
  ) {}

  signUp() {
    this.httpClient
      .post(
        `${environment.baseAuthUrl}/signup`,
        { email, password }, // <- this should come from registerStore.email$ and registerStore.password$
      )
  }
}

When you use signUp you trigger it, so you need to use the CURRENT STORE STATE VALUES of email and password, it is unclear what store solution you use but it can be something like: registerStore.state.email which returns the current value and NOT該值的可觀察值

signUp() {
    this.httpClient
      .post(
        `${environment.baseAuthUrl}/signup`,
        { registerStore.state.email, registerStore.state.password }, // <- this should come from registerStore.email$ and registerStore.password$
      )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM