iT邦幫忙

0

第41天~

Tzu 2021-08-21 15:37:101144 瀏覽
  • 分享至 

  • xImage
  •  

這個得上一篇:https://ithelp.ithome.com.tw/articles/10258409

這裡要做放入購物車要結帳的清單

用cmd語法新增component:ng generate service services/cart

https://ithelp.ithome.com.tw/upload/images/20210824/20119035eGr1WeJWbc.png

這裡從app.module.ts檔案增加Routes
會自動import:
https://ithelp.ithome.com.tw/upload/images/20210824/20119035dKhjnJPXo9.png

然後從cart-status.component.html檔案增加購物車的ICON
所以修正 <a href="shopping-detail.html">語法
https://ithelp.ithome.com.tw/upload/images/20210824/20119035VtJ9okfjfh.png
變成<a routerLink="/cart-details">:
https://ithelp.ithome.com.tw/upload/images/20210824/20119035Dd7biQyZ40.png

從cart-details.component.html檔案加入div語法:

https://ithelp.ithome.com.tw/upload/images/20210824/20119035IGg32eaxqz.png

按住購物車顯示:
https://ithelp.ithome.com.tw/upload/images/20210824/20119035X7B1fRmvE0.png

然後到cart-details.component.html檔案慢慢加入語法變成有表格:

<div class="main-content">
  <div class="section-content section-content-p30">
    <div class="container-fluid">

      <table class="table tabled-bordered">
        <tr>

           <th width="20%">產品照片</th>
           <th width="50%">產品明細</th>
           <th width="30%"></th>

        </tr>


      </table>



    </div>

  </div>


</div>

目前長這樣:
https://ithelp.ithome.com.tw/upload/images/20210824/20119035zfKacvNQUe.png

然後到cart-details.component.html檔案慢慢更改成CSS語法:

<table class="table table-bordered">

表格底部就變成藍色了
/images/emoticon/emoticon04.gif
https://ithelp.ithome.com.tw/upload/images/20210824/20119035NkTI3b890x.png

然後到cart-details.component.ts檔案.這裡 也是要按listCartDetails浮在上面修正=宣告方法:

https://ithelp.ithome.com.tw/upload/images/20210824/20119035FurLy2ZbrP.png
變成:

import { CartItem } from 'src/app/common/cart-item';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-cart-details',
  templateUrl: './cart-details.component.html',
  styleUrls: ['./cart-details.component.css']
})
export class CartDetailsComponent implements OnInit {

  CartItem: CartItem[] =[];
  totalPrice: number =0;
  totalQuantity: number =0;




  constructor() { }

  ngOnInit(): void {
    this.listCartDetails();
  }
  listCartDetails() {
    throw new Error("Method not implemented.");
  }

}

然後再到檔案方法裡面的語法=項目+價格=加總:
這裡有發生CartItems大小寫不同會反紅.再看後面是否會有影響

import { CartService } from './../../services/cart.service';
import { CartItem } from 'src/app/common/cart-item';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-cart-details',
  templateUrl: './cart-details.component.html',
  styleUrls: ['./cart-details.component.css']
})
export class CartDetailsComponent implements OnInit {

  cartItems: CartItem[] =[];
  totalPrice: number =0;
  totalQuantity: number =0;




  constructor(private CartService: CartService) { }

  ngOnInit(): void {
    this.listCartDetails();
  }
  listCartDetails() {

    this.cartItems = this.CartService.CartItems;

    this.CartService.totalPrice.subscribe(
      data =>this.totalPrice = data

    );

    this.CartService.totalQuantity.subscribe(

      data =>this.totalPrice = data

    );

    this.CartService.computeCartTotals();




  }

}

這個得下一篇:https://ithelp.ithome.com.tw/articles/10258476


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言