第41天~

这个得上一篇: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


<<:  解决 "No manual entry for gcc" 的记录

>>:  Rails幼幼班--Active Record?

Day18 PHP的常用函数3:时间函数

时间函数 世界各国表示时间的方式不一样,存储不方便,计算不方便,不同的时间表示方式影响,不利於沟通和...

EP09 - 建立 Django 专案和 EC2 环境 并手动部署到 EC2

前几天的打底, 把 Gitlab、Jenkins 建好, 但是仍然少了最重要的主角, 要部署的服务本...

Day.4 针对使用者做管理 - 权限管理&资安 (Power)

在资料库管理上,root 相当於拥有所有权限的最大管理者,针对不同使用者规划给予相应的权限是很重要的...

Day20 AR抬头显示器(HUD)与一般的差异 你是5岁就抬头还是3岁才抬头的呢?

这期要介绍抬头显示器(HUD)的一些功能和种类,让我们马上开始。 抬头显示器可用於汽车上。它将讯息投...

[ Day 16 ] React Hooks 中的 useEffect

昨天介绍了在 Function Component 中该如何操作 state 的方法(附上传送门)...