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
984f587d
"...android/gradle/wrapper/gradle-wrapper.properties" did not exist on "5987c1e35802611d404a107f2fb24860dd65644f"
Commit
984f587d
authored
Dec 20, 2018
by
李彥志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parent
b40bd8a6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
22 deletions
+102
-22
src/app/app.component.css
src/app/app.component.css
+3
-0
src/app/app.component.html
src/app/app.component.html
+41
-20
src/app/app.component.ts
src/app/app.component.ts
+39
-1
src/app/app.module.ts
src/app/app.module.ts
+4
-1
src/app/message.ts
src/app/message.ts
+15
-0
No files found.
src/app/app.component.css
View file @
984f587d
.btn-space
{
margin-right
:
5px
;
}
src/app/app.component.html
View file @
984f587d
<!--The content below is only a placeholder and can be replaced.-->
<form
(ngSubmit)=
"addMessage()"
>
<div
style=
"text-align:center"
>
<p>
<h1>
單品:
<input
type=
"text"
name=
"name"
[(ngModel)]=
"name"
><br>
Welcome to {{ title }}!
單價:
<input
type=
"number"
name=
"price"
min=
"1"
[(ngModel)]=
"price"
><br>
</h1>
數量:
<input
type=
"number"
name=
"quantity"
min=
"1"
[(ngModel)]=
"quantity"
><br>
<img
width=
"300"
alt=
"Angular Logo"
src=
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="
>
</p>
</div>
{{message}}
<h2>
Here are some links to help you start:
</h2>
<button
type=
"submit"
class=
"btn btn-space"
>
新增項目
</button>
<ul>
<button
type=
"reset"
ng-click=
" remove()"
>
清空所有項目
</button>
<li>
</form>
<h2><a
target=
"_blank"
rel=
"noopener"
href=
"https://angular.io/tutorial"
>
Tour of Heroes
</a></h2>
</li>
<table
border=
"1"
>
<li>
<tr>
<h2><a
target=
"_blank"
rel=
"noopener"
href=
"https://angular.io/cli"
>
CLI Documentation
</a></h2>
<th>
動作
</th>
</li>
<th>
商品名稱
</th>
<li>
<th>
商品價格
</th>
<h2><a
target=
"_blank"
rel=
"noopener"
href=
"https://blog.angular.io/"
>
Angular blog
</a></h2>
<th>
購買數量
</th>
</li>
<th>
小計
</th>
</ul>
</tr>
<!-- 清單 -->
<ng-container
*ngFor=
"let message of messages"
>
<tr>
<td><button
type=
"reset"
>
刪除
</button></td>
<td>
{{ message.name }}
</td>
<td>
{{ message.price }}
</td>
<td>
{{ message.quantity }}
</td>
<td>
{{ message.price * message.quantity}}
</td>
</tr>
</ng-container>
<tr>
<td
colspan=
"4"
align=
"right"
>
加總
</td>
<td></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> -->
<router-outlet></router-outlet>
src/app/app.component.ts
View file @
984f587d
import
{
Component
}
from
'
@angular/core
'
;
import
{
Component
}
from
'
@angular/core
'
;
import
{
Message
}
from
'
./message
'
;
@
Component
({
@
Component
({
selector
:
'
app-root
'
,
selector
:
'
app-root
'
,
...
@@ -6,5 +7,42 @@ import { Component } from '@angular/core';
...
@@ -6,5 +7,42 @@ import { Component } from '@angular/core';
styleUrls
:
[
'
./app.component.css
'
]
styleUrls
:
[
'
./app.component.css
'
]
})
})
export
class
AppComponent
{
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
);
}
}
}
src/app/app.module.ts
View file @
984f587d
...
@@ -4,13 +4,16 @@ import { NgModule } from '@angular/core';
...
@@ -4,13 +4,16 @@ import { NgModule } from '@angular/core';
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
{
FormsModule
}
from
'
@angular/forms
'
;
@
NgModule
({
@
NgModule
({
declarations
:
[
declarations
:
[
AppComponent
AppComponent
],
],
imports
:
[
imports
:
[
BrowserModule
,
BrowserModule
,
AppRoutingModule
AppRoutingModule
,
FormsModule
],
],
providers
:
[],
providers
:
[],
bootstrap
:
[
AppComponent
]
bootstrap
:
[
AppComponent
]
...
...
src/app/message.ts
0 → 100644
View file @
984f587d
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
;
}
}
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