[英]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.