所以我有一个普通的堆栈应用程序,其中包含并订购包含以下内容的数组:名称,描述,成本,状态。
我打算在此表中添加“新订单”,并希望更新该表中所有成本之和的总成本。并非100%如何做到这一点。
**Here is my html**
https://i.stack.imgur.com/I28ze.png
**HERE is the typescript file:**
import { Component, OnInit } from '@angular/core';
import { ApiService } from './../../service/api.service';
@Component({
selector: 'app-order-list',
templateUrl: './order-list.component.html',
styleUrls: ['./order-list.component.css']
})
export class OrderListComponent implements OnInit {
Order: any = [];
constructor(private apiService: ApiService) {
this.readOrder();
}
ngOnInit() {}
readOrder(){
this.apiService.getOrders().subscribe((data) => {
this.Order = data;
});
}
removeOrder(order, index) {
if (window.confirm('Are you sure?')) {
this.apiService.deleteOrder(order._id).subscribe((data) => {
this.Order.splice(index, 1);
}
);
}
}
}
**and here is the orders arrary:**
export class Order {
name: string;
description: string;
cost: number;
status: string;
}