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

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