app.component.ts 816 Bytes
Newer Older
李彥志's avatar
李彥志 committed
1
import { Component } from '@angular/core';
李彥志's avatar
李彥志 committed
2
import { Message } from './message';
李彥志's avatar
李彥志 committed
3 4 5 6 7 8 9

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
李彥志's avatar
李彥志 committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

  name = '';

  price = '';

  quantity = '';

  messages: Message[] = [];

  addMessage(): void {

 // 防呆,避免名稱或內容是空值時也可以留言
  if (
    !this.name.trim() && !this.messages.trim() && !this.quantity.trim()
  ) {
    return;
  }

  // 用名稱跟內容產生一個留言的資料物件
  const message = new Message(this.name, this.price, this.quantity);

  // 將留言的資料物件放進容器裡
  this.messages.push(message);

}

  total():void {
  }

  buildMessage(): void {

  }

  remove(): void {
    this.messages.remove(new Message);
  }


李彥志's avatar
李彥志 committed
48
}