p2.component.html 1.12 KB
Newer Older
李彥志's avatar
李彥志 committed
1
<p style="color:green">題二</p>
李彥志's avatar
李彥志 committed
2
<form (ngSubmit)="addData()">
李彥志's avatar
李彥志 committed
3
<p>
李彥志's avatar
李彥志 committed
4
  單品:<input type="text" name="name" [(ngModel)]="name" ><br>
李彥志's avatar
李彥志 committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  單價:<input type="number" name="price" min="1" [(ngModel)]="price"><br>
  數量:<input type="number" name="quantity" min="1" [(ngModel)]="quantity"><br>
  你購買 {{ name }} 商品,單價 {{ price }} 元,數量{{ quantity }}元,共計NT${{ price * quantity}} 元
</p>
  <button type="submit" class="btn btn-space">新增項目</button>
  <button type="reset">清空所有項目</button>
</form>

<table border="1" >
  <tr>
    <th>動作</th>
    <th>商品名稱</th>
    <th>商品價格</th>
    <th>購買數量</th>
    <th>小計</th>
  </tr>
  <!-- 清單 -->
李彥志's avatar
李彥志 committed
22
  <ng-container *ngFor="let data of datas; let i = index">
李彥志's avatar
李彥志 committed
23
  <tr>
李彥志's avatar
李彥志 committed
24 25 26 27 28
    <td><button (click)="deleteItem(data)">刪除</button></td>
    <td>{{ data.name }}</td>
    <td>{{ data.price }}</td>
    <td>{{ data.quantity }}</td>
    <td>{{ data.price * data.quantity}}</td>
李彥志's avatar
李彥志 committed
29 30 31 32
  </tr>
</ng-container>
  <tr>
    <td colspan="4" align="right">加總</td>
李彥志's avatar
李彥志 committed
33
    <td>{{ totalPrice() }}</td>
李彥志's avatar
李彥志 committed
34 35 36 37
  </tr>
</table>
<br>
<router-outlet></router-outlet>