Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AngularPractice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
李彥志
AngularPractice
Commits
537ec559
Commit
537ec559
authored
Dec 21, 2018
by
李彥志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
984f587d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
27 deletions
+10
-27
src/app/P2.html
src/app/P2.html
+0
-0
src/app/app.component.html
src/app/app.component.html
+5
-12
src/app/app.component.ts
src/app/app.component.ts
+5
-15
No files found.
src/app/P2.html
0 → 100644
View file @
537ec559
src/app/app.component.html
View file @
537ec559
...
...
@@ -3,10 +3,10 @@
單品:
<input
type=
"text"
name=
"name"
[(ngModel)]=
"name"
><br>
單價:
<input
type=
"number"
name=
"price"
min=
"1"
[(ngModel)]=
"price"
><br>
數量:
<input
type=
"number"
name=
"quantity"
min=
"1"
[(ngModel)]=
"quantity"
><br>
你購買 {{ name }} 商品,單價 {{ price }} 元,數量{{ quantity }}元,共計NT${{ price * quantity}} 元
</p>
{{message}}
<button
type=
"submit"
class=
"btn btn-space"
>
新增項目
</button>
<button
type=
"reset"
ng-click=
" remove()"
>
清空所有項目
</button>
<button
type=
"reset"
>
清空所有項目
</button>
</form>
<table
border=
"1"
>
...
...
@@ -18,9 +18,9 @@
<th>
小計
</th>
</tr>
<!-- 清單 -->
<ng-container
*ngFor=
"let message of messages"
>
<ng-container
*ngFor=
"let message of messages
; let i = index
"
>
<tr>
<td><button
type=
"reset
"
>
刪除
</button></td>
<td><button
(click)=
"deleteItem(item)
"
>
刪除
</button></td>
<td>
{{ message.name }}
</td>
<td>
{{ message.price }}
</td>
<td>
{{ message.quantity }}
</td>
...
...
@@ -29,14 +29,7 @@
</ng-container>
<tr>
<td
colspan=
"4"
align=
"right"
>
加總
</td>
<td></td>
<td>
{{total}}
</td>
</tr>
</table>
<!-- <ng-container *ngFor="let message of messages">
<p>商品名稱:{{ message.name }}</p>
<p>商品價格:{{ message.price }}</p>
<p>購物數量:{{ message.quantity }}</p>
<p>小計:{{ message.price * message.quantity}}</p>
</ng-container> -->
src/app/app.component.ts
View file @
537ec559
...
...
@@ -16,33 +16,23 @@ export class AppComponent {
messages
:
Message
[]
=
[];
result
=
0
;
addMessage
():
void
{
// 防呆,避免名稱或內容是空值時也可以留言
if
(
!
this
.
name
.
trim
()
&&
!
this
.
messages
.
trim
()
&&
!
this
.
quantity
.
trim
()
!
this
.
name
.
trim
()
&&
!
this
.
price
.
trim
()
&&
!
this
.
quantity
.
trim
()
)
{
return
;
}
// 用名稱跟內容產生一個留言的資料物件
const
message
=
new
Message
(
this
.
name
,
this
.
price
,
this
.
quantity
);
// 將留言的資料物件放進容器裡
this
.
messages
.
push
(
message
);
}
total
():
void
{
deleteItem
():
void
{
alert
(
'
清空啦
'
);
}
buildMessage
():
void
{
}
remove
():
void
{
this
.
messages
.
remove
(
new
Message
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment