iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 30
0

居然是最後一天/images/emoticon/emoticon02.gif

真沒想到我是這樣撐到最後的
其實我本來真的是想要很老實地寫的/images/emoticon/emoticon09.gif
但是/images/emoticon/emoticon20.gif

謝謝持續追蹤的各位/images/emoticon/emoticon24.gif

後面應該會持續新增:
接續著search這個功能:
https://ithelp.ithome.com.tw/upload/images/20210731/2011903521yUd51DII.png

把中間這段先註釋掉:
https://ithelp.ithome.com.tw/upload/images/20210731/20119035GO2jUUswev.png

https://ithelp.ithome.com.tw/upload/images/20210731/20119035TnUsYsMDtu.png


呈現search works!代表成功作動
https://ithelp.ithome.com.tw/upload/images/20210731/20119035jgFhNwH22L.png

把原來註解的 剪下:

<!--
            <form class="form-header" onsubmit="return false;" method="GET">
              <input class="au-input au-input-xl" type="text" name="search"
                placeholder="Search for data ..." />
              <button class="au-btn-submit" type="submit">
                Search
              </button>
            </form>
           -->

https://ithelp.ithome.com.tw/upload/images/20210731/20119035a363lvZ9Fo.png

貼到search.component.html檔案

https://ithelp.ithome.com.tw/upload/images/20210731/20119035gYd4aq8vZN.png

改一些語法不再用form用div其他改成用手輸入的語法:
doSearch剛打完會反紅不用緊張

https://ithelp.ithome.com.tw/upload/images/20210731/20119035LNRIPH7kYp.png

因為是沒有到search.component.ts去宣告
https://ithelp.ithome.com.tw/upload/images/20210731/2011903525TQe5COCZ.png

到product-list.component.ts檔案增加

import { Component, OnInit } from '@angular/core';
import { ProductService } from 'src/app/services/product.service';
import { Product } from 'src/app/common/product';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-product-list',

  templateUrl: './product-list-grid.component.html',

  styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {

  products: Product[];
  currentCategoryId: number;
  searchMode:boolean;



  constructor(private productService: ProductService,
              private Route: ActivatedRoute) { }

  // tslint:disable-next-line: typedef
  ngOnInit() {
    this.Route.paramMap.subscribe(() => {
    this.listProducts();
  });
  }

  // tslint:disable-next-line: typedef
  listProducts() {

    const hasCategoryId : boolean =this.Route.snapshot.paramMap.has('id');

    if(hasCategoryId){
      this.currentCategoryId = +this.Route.snapshot.paramMap.get('id');
    }
    else{
      this.currentCategoryId = 1;
    }

    this.productService.getProductList(this.currentCategoryId).subscribe(
      data => {
        this.products = data;
      }
    )
  }

  handleListProducts(){
    
  }
}

然後剪掉這裡
https://ithelp.ithome.com.tw/upload/images/20210731/20119035MqTyQhKHgV.png
搬到下面然後新增keyword搜尋的變數:

import { Component, OnInit } from '@angular/core';
import { ProductService } from 'src/app/services/product.service';
import { Product } from 'src/app/common/product';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-product-list',

  templateUrl: './product-list-grid.component.html',

  styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {

  products: Product[];
  currentCategoryId: number;
  searchMode:boolean;



  constructor(private productService: ProductService,
              private Route: ActivatedRoute) { }

  // tslint:disable-next-line: typedef
  ngOnInit() {
    this.Route.paramMap.subscribe(() => {
    this.listProducts();
  });
  }

  // tslint:disable-next-line: typedef
  listProducts() {

    this.searchMode = this.Route.snapshot.paramMap.has('keyword');

    if(this.searchMode){
      this.handleSearchProducts();
    }
    else{
      this.handleListProducts();
    }


     }

     handleSearchProducts(){

      const theKeyword: string =this.Route.snapshot.paramMap.get('keyword');

      this.productService.searchProducts(theKeyword).subscribe(

        data =>{
          this.products = data;

        }

      );


     }



  handleListProducts(){
    const hasCategoryId : boolean =this.Route.snapshot.paramMap.has('id');

    if(hasCategoryId){
      this.currentCategoryId = +this.Route.snapshot.paramMap.get('id');
    }
    else{
      this.currentCategoryId = 1;
    }

    this.productService.getProductList(this.currentCategoryId).subscribe(
      data => {
        this.products = data;
      }
    )
  }
}



接著寫searchProducts反紅處理

https://ithelp.ithome.com.tw/upload/images/20210731/20119035YizlecED9L.png

在紅色上面右鍵"宣告方法"
https://ithelp.ithome.com.tw/upload/images/20210731/20119035xZmEW4XWhh.png

還是有反紅的地方
https://ithelp.ithome.com.tw/upload/images/20210731/20119035IqTa9ukAjO.png

再到product.service.ts檔案

  searchProducts(theKeyword: string) {
    throw new Error("Method not implemented.");
  }
  

剪掉

https://ithelp.ithome.com.tw/upload/images/20210731/20119035bTZT0hWMVj.png

後面就是大改code


延續昨天的閒聊 就是用JAVA加密..這個書很少寫耶~

金鑰:要解15年但...量子電腦1秒
keytool -genkeypair -alias tomcat -keyalg RSA -keypass 123456 -storepass 123456 -keysize 1024 -validity 365 -keystore %CATALINA_BASE%\conf\keys\tomcat.keystore

也是正常版就刪掉
祝大家中秋節快樂

明天無法見了/images/emoticon/emoticon26.gif


雖然第12屆的IT邦幫忙結束~或許我會後面寫怎麼部屬上heroku?第31天?@@

第31篇在https://ithelp.ithome.com.tw/articles/10233130


上一篇
倒數第2天
系列文
把前後分離製作的網站組起來30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
peace&love
iT邦新手 4 級 ‧ 2021-04-11 00:03:38

這甚麼啦XDDDD~~~~

Tzu iT邦研究生 5 級 ‧ 2021-07-31 22:04:26 檢舉

/images/emoticon/emoticon47.gif

我要留言

立即登入留言