首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ionic-3中执行CRUD操作?

如何在Ionic-3中执行CRUD操作?
EN

Stack Overflow用户
提问于 2019-03-14 18:32:52
回答 1查看 255关注 0票数 0

我想知道如何以从的形式插入来自用户的数据,并使用jsonserver执行crud应用程序how can I do it.is my rest.ts file

代码语言:javascript
复制
    // page with the api 
    public getProducts(): Observable<any> {
      return this.http
      .get(this.baseUrl + '/products')
    }

这是我的list.ts文件

代码语言:javascript
复制
//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文件

代码语言:javascript
复制
 //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>
EN

回答 1

Stack Overflow用户

发布于 2019-03-15 13:23:59

您不能期望有人为您实现整个CRUD应用程序。我建议你从一开始就给Ionic Academy看看。

一些指导原则:

  • 你需要把所有的逻辑放在一个地方(通常是调用的服务)
  • ,然后你需要创建存储服务来存储数据,不管它是本地存储,就像教程中的或者是一个数据库。我建议坚持使用本地存储,直到你把事情弄清楚,因为它们是你的朋友。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55160278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档