diff --git a/src/app/app.component.css b/src/app/app.component.css
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a4299bec1790b10319c87c807f556d3b7fc5e821 100644
--- a/src/app/app.component.css
+++ b/src/app/app.component.css
@@ -0,0 +1,3 @@
+.btn-space {
+ margin-right: 5px;
+}
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 0f3d9d8b9f8e1a938befbfea5ac8bc11494ea709..d9292d73ce06614208d6abd0a11311094cb9bb17 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -1,21 +1,42 @@
-
-
-
- Welcome to {{ title }}!
-
-

-
-Here are some links to help you start:
-
+
+
+
+
+ 動作 |
+ 商品名稱 |
+ 商品價格 |
+ 購買數量 |
+ 小計 |
+
+
+
+
+ |
+ {{ message.name }} |
+ {{ message.price }} |
+ {{ message.quantity }} |
+ {{ message.price * message.quantity}} |
+
+
+
+ 加總 |
+ |
+
+
+
-
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 0c63d2a7afd9cea43610c31692408277deeda00a..7ff3fd279763541bc1e422340ea444bece30b830 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
+import { Message } from './message';
@Component({
selector: 'app-root',
@@ -6,5 +7,42 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.css']
})
export class AppComponent {
- title = 'P2';
+
+ 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);
+ }
+
+
}
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 2c3ba2995c8510c02ca812f90280146738f162cf..39fb9f35a1dbfa7ef92b37fed5653c6835965ca4 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -4,13 +4,16 @@ import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
+import { FormsModule } from '@angular/forms';
+
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
- AppRoutingModule
+ AppRoutingModule,
+ FormsModule
],
providers: [],
bootstrap: [AppComponent]
diff --git a/src/app/message.ts b/src/app/message.ts
new file mode 100644
index 0000000000000000000000000000000000000000..6c308270be757b455c303d3992b6358dd85c6f24
--- /dev/null
+++ b/src/app/message.ts
@@ -0,0 +1,15 @@
+export class Message {
+
+ name: string;
+ price: string;
+ quantity: string;
+
+ constructor(name: string, price: string, quantity: string) {
+
+ this.name = name;
+ this.price = price;
+ this.quantity = quantity;
+
+ }
+
+}