首页 > 解决方案 > 使用 Angular 一键传递/检索多行

问题描述

我能够以数组的形式传递数据,但不能以数组的形式检索它。我传递的数据没有作为数组存储在 json 文件中。我使用 finalList 作为数组,向其中插入数据,然后使用订阅者将其推送到 api。

.html 代码:

 <button style="border: 1px solid white" type="button"  name="button"  (click)="add({basic_amount:basic_amount.value,purchase:purchase.value,license:license.value,Particulars:Particulars.value,Quantity :Quantity.value,users :users.value}, regForm)"><i class="fa fa-plus" aria-hidden="true"></i> </button>

.ts 代码:

    add(a, regForm) {
        this.addService.add(a).subscribe((res: Response) => [
             this.finalList.push(a),
             regForm.reset(),
             this.basic_cost
         ]);

  }

邮政编码服务:

   add(data) {
      const url = 'http://localhost:3000/item';
       const headers = new HttpHeaders({'Content-Type': 'application/json'});
    return this.http.post(url, data, {headers: headers});

  }

获得服务

 private URL = 'http://localhost:3000/item';
 item(): Observable <any> {
 console.log('Observable');
 return this.http.get<any>(this.URL);

}

标签: angular

解决方案


推荐阅读