繁体   English   中英

服务器上的 Angular Post Reactive Form

[英]Angular Post Reactive Form on server

您好,我正在尝试向服务器添加一个项目,但我在将其发送到服务器时遇到了困难

这是一些代码片段

public onOkClick(priceListItemDTO): void {
    this.dialogRef.close();
    this.itemsService.AddItems(this.profileForm)
      .subscribe(params => {
        priceListItemDTO = this.profileForm;
      });
  }

onOkClick 在我的项目服务中使用了这个功能(这里可能有一个错误,但我很确定没有。也许是一个小错误

public AddItems(priceListItemDTO: FormGroup): Observable<PriceListItemDTO[]> {
  return this.apiService.post<PriceListItemDTO[]>(
  '/price-lists/' + ItemsService.PRICE_LIST_ID + '/items', priceListItemDTO);

并且 AddItems 使用 ApiService 这是 100% 正确的

public post<T>(endpoint: string, params = null): Observable<T> {
    return this.http.post<T>(ApiService.URL + endpoint, params, {headers: this.getRequestHeaders()})
      .pipe(tap(null, err => this.interceptError(err)));
  }

因此,我正在尝试创建另一个我尝试过的项目,我确定 From 是正确的,并且我也尝试使用 push 的第一个代码片段中存在错误,但我也失败了。 如果你需要我澄清一些事情,我很乐意这样做

如您所见,这需要进行一些更改

 priceListItemDTO: PriceListItemDTO[];   
     public onOkClick(): void {
            this.dialogRef.close();
            this.itemsService.AddItems(this.profileForm.value)
              .subscribe(params => {
                this.priceListItemDTO.push(this.profileForm.value);
              });
          }

在这里它只需要形成阵列

public AddItems(priceListItemDTO: FormArray, plu: number): Observable<PriceListItemDTO[]> {
  return this.apiService.post<PriceListItemDTO[]>(
  '/price-lists/' + ItemsService.PRICE_LIST_ID + '/items', priceListItemDTO);

现在一切都按预期工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM