显示和隐藏输入字段

用户10102331

我正在尝试制作一个表格行正下方的表格。我知道我的表格格式不正确,但我正在尝试同时解决多个问题。我对 angular 很陌生,我只去过一次英雄之旅。我需要构建一个 java 后端和 Angular 前端,所以请注意这一点。我想在单击我的编辑时显示我的一个表单,但所有表单都弹出。我无法链接 stackblitz,因为我确实尝试过,因为某些原因它不允许我这样做。如果您对我想做什么有任何疑问,请告诉我。给出的第一个答案没有回答我的问题,所以请提交更多。

home.component.html

 <div class="table-responsive">
        <table  class="table table-bordered table-striped">
          <thead>
          <tr>
            <th>Id</th>
            <th>Product</th>
            <th>Category</th>
            <th>FullPrice <i id ="asc-desc1"class="fas fa-angle-down" (click)="SortPrice($event)"></i></th>
            <th>Saleprice <i id ="asc-desc2"class="fas fa-angle-down" (click)="SortSale($event)"></i> </th>
            <th>Supplier</th>
            <th>Discount<i id ="asc-desc3"class="fas fa-angle-down" (click)="SortDiscount($event)"></i></th>
            <th>Edit</th>
          </tr>
          </thead>
          <tbody  *ngFor="let home of home | paginate:{itemsPerPage:20,currentPage: p}" >
          <tr *ngIf="!editMode">
            <td >{{home.id}}</td>
            <td>{{home.productName}}</td>
            <td>{{home.category.categoryName}}</td>
            <td>{{home.fullPrice}}</td>
            <td>{{home.salePrice}}</td>
            <td>{{home.supplier.supplierName}}</td>
            <td>{{home.discount }}</td>
            <td class="text-right" id="tableDataBtns">
              <div class="btn-group" role="group">
                <button  (click)="editMode=true" type="button" class="btn btn-secondary"><i class="far fa-edit"></i></button>
                <button type="button" class="btn btn-danger"><i class="far fa-trash-alt"></i></button>
              </div>
            </td>
          </tr>
          <tr *ngIf="editMode">
          <td><input placeholder="{{home.id}}"/></td>
          <td><input placeholder="{{home.productName}}"/></td>
          <td><input placeholder="{{home.category.categoryName}}"/></td>
          <td><input placeholder="{{home.fullPrice}}"/></td>
          <td><input placeholder="{{home.salePrice}}"/></td>
          <td><input placeholder="{{home.supplier.supplierName}}"/></td>
          <td><input placeholder="{{home.discount }}"/></td>
          <td class="text-right" id="tableDataBtns">
            <div class="btn-group" role="group">
              <button  (click)="editMode=true" type="button" class="btn btn-secondary"><i class="far fa-edit"></i></button>
              <button type="button" class="btn btn-danger"><i class="far fa-trash-alt"></i></button>
            </div>
          </td>
        </tr>


          </tbody>
        </table>
        <pagination-controls class="myPagination" (pageChange)="p= $event"></pagination-controls>
      </div>

我想要什么 我只想要能够显示和编辑一个产品在此处输入图片说明我不处于编辑模式当我不在编辑模式时时的外观 我处于编辑模式时的外观 所有表格显示 我只想要一个这是当我单击编辑模式时发生的所有产品都是可编辑的 我只需要一个产品是可编辑的

AJT82

如果您想一次打开一个编辑,您需要为每个项目有一个唯一的标识符。您可以借助布尔变量和模板中的迭代索引来完成。这是您的代码的简化示例,我们使用editMode您拥有的变量,但让我们也附加索引:

<table>
    <tr>
        <th>Product</th>
        <th>Category</th>
    <th></th>
    </tr>
    <tr *ngFor="let item of items; index as i">
        <ng-container *ngIf="editMode !== i">
            <td>{{item.productName}}</td>
            <td>{{item.categoryName}}</td>
        </ng-container>
        <! -- if assigned index to editMode matches -->
        <ng-container *ngIf="editMode === i">
            <td><input [(ngModel)]="item.productName" /></td>
            <td><input [(ngModel)]="item.categoryName" /></td>
        </ng-container>
    <td>
      <!-- Assign the index to edit mode, which item clicked -->
      <button (click)="editMode = i">Edit</button>
    </td>
    </tr>
</table>

完成编辑后,只需设置editModefalse.

这是一个 STACKBLITZ

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

隐藏/显示输入字段 asp

来自分类Dev

隐藏和显示列字段

来自分类Dev

如何隐藏/显示用户选择的输入字段?

来自分类Dev

如何在Flutter中显示带有提交按钮和隐藏输入字段的HTML表单

来自分类Dev

jQuery-显示/隐藏隐藏的输入表单字段

来自分类Dev

选择后显示和隐藏表单的字段

来自分类Dev

隐藏和显示单击javascript的输入

来自分类Dev

根据用户输入显示和隐藏DIV

来自分类Dev

jQuery隐藏和显示文本输入

来自分类Dev

显示/隐藏/禁用表单输入和 div

来自分类Dev

如何使jquery序列化忽略div中隐藏和显示之间切换的输入字段

来自分类Dev

显示/隐藏公共输入字段,然后发布到php

来自分类Dev

根据用户输入在Pentaho报告中显示/隐藏字段

来自分类Dev

根据输入字段的填充事件显示隐藏的按钮

来自分类Dev

在下拉列表中选择值显示隐藏的输入字段

来自分类Dev

如何根据输入文本字段隐藏或显示类

来自分类Dev

当输入字段为空时显示/隐藏div(jquery,javascript)

来自分类Dev

在附加元素内显示/隐藏输入字段

来自分类Dev

输入字段和gldatepicker显示间隙

来自分类Dev

Cakephp隐藏的输入字段

来自分类Dev

隐藏输入字段的标签

来自分类Dev

键入隐藏的输入字段

来自分类Dev

隐藏时间和日期输入字段的错误消息

来自分类Dev

我如何先隐藏输入字段并先隐藏标签,然后在单击按钮时显示

来自分类Dev

使用CSS和jQuery隐藏/显示表单字段

来自分类Dev

使用jQuery隐藏和显示HTML中的字段

来自分类Dev

使用CSS和jQuery隐藏/显示表单字段

来自分类Dev

如何根据选择隐藏和显示 HTML 中的字段

来自分类Dev

使用 onblur 在字段下方显示和隐藏消息

Related 相关文章

热门标签

归档