我想知道如何以从的形式插入来自用户的数据,并使用jsonserver执行crud应用程序how can I do it.is my rest.ts file
// page with the api
public getProducts(): Observable<any> {
return this.http
.get(this.baseUrl + '/products')
}这是我的list.ts文件
//page to shown
onCreateProduct(product)
{
console.log(this.product);
this.restProvider
.createProduct(product)
.subscribe(
(newProduct) => {
this.products=this.product.push(newProduct);
this.products = this.products.concat(newProduct);
}
);
}这是我的list.html文件
//page with the form handling
<form (ngSubmit)="onCreateProduct(product)" #product="ngForm" class="list-form">
<table>
<tr>
<td>Enter name</td>
<td>
<ion-input [(ngModel)]="product.name" class="form-control" name="name" type="text" #name="ngModel">
</ion-input>
</td>
</tr>
<tr>
<td>Enter cost</td>
<td><ion-input[(ngModel)]="product.cost" class="form-control" name="cost" type="text" #cost="ngModel">
</ion-input>
</td>
</tr>
<tr>
<td colspan="2">
<button ion-button >CREATE</button>
</td>
</tr>
</table>
</form>
<br/>
</div>
<h3>Product Details</h3>
<table>
<tr>
<th> Id</th>
<th>Product_name</th>
<th>Product_cost</th>
<th></th><th><th></th>
</tr>
<tr *ngFor="let product of products" >
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.cost}}</td>
<button ion-button (click)="onEditProduct(product)">Edit </button>
</td>
<td>
<button ion-button (click)="onRemoveProduct(product)">Delete </button>
</td>
<td>
<button ion-button (click)="onUpdateProduct(product)">UPDATE </button>
</td>
</tr>
</table>发布于 2019-03-15 13:23:59
您不能期望有人为您实现整个CRUD应用程序。我建议你从一开始就给Ionic Academy看看。
一些指导原则:
https://stackoverflow.com/questions/55160278
复制相似问题