Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
WeatherAPI
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ly Trịnh Khánh
WeatherAPI
Commits
2b300ce5
Commit
2b300ce5
authored
Apr 27, 2023
by
DangSauQuaKhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add array city
parent
a78baa58
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
26 deletions
+45
-26
app-routing.module.ts
src/app/app-routing.module.ts
+1
-1
app.component.html
src/app/app.component.html
+1
-1
app.component.ts
src/app/app.component.ts
+2
-0
today.component.html
src/app/today/today.component.html
+34
-23
today.component.ts
src/app/today/today.component.ts
+7
-1
No files found.
src/app/app-routing.module.ts
View file @
2b300ce5
...
...
@@ -7,7 +7,7 @@ const routes: Routes = [
{
path
:
'
:slug
'
,
component
:
Anothercit
yComponent
,
component
:
Toda
yComponent
,
}
];
...
...
src/app/app.component.html
View file @
2b300ce5
...
...
@@ -2,5 +2,5 @@
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
integrity=
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin=
"anonymous"
>
</head>
<div
class=
"container"
>
<app-today></app-today>
<app-today
[cities]=
"cities"
></app-today>
</div>
src/app/app.component.ts
View file @
2b300ce5
import
{
Component
}
from
'
@angular/core
'
;
import
{
ActivatedRoute
}
from
'
@angular/router
'
;
import
{
ShareReplayConfig
}
from
'
rxjs
'
;
@
Component
({
selector
:
'
app-root
'
,
...
...
@@ -8,5 +9,6 @@ import { ActivatedRoute } from '@angular/router';
})
export
class
AppComponent
{
title
=
'
weatherAPI
'
;
cities
:
any
[]
=
new
Array
();
constructor
(
private
_route
:
ActivatedRoute
){}
}
src/app/today/today.component.html
View file @
2b300ce5
...
...
@@ -2,33 +2,44 @@
<div
class=
"col-md-6 offset-md-3 "
>
<div
class=
"col-sm-12 text-center"
>
<div
class=
"input-group mt-5"
>
<input
type=
"text"
class=
"form-control"
#userInput
placeholder=
"city name"
(keyup.enter)=
"getCity(userInput.value)"
>
<input
type=
"text"
class=
"form-control"
#userInput
placeholder=
"city name"
(keyup.enter)=
"getCity(userInput.value)"
>
<div
class=
"input-group-append"
>
<button
class=
"input-group-text btn btn-outline-primary"
(click)=
"getCity(userInput.value)"
>
Search
</button>
<button
class=
"input-group-text btn btn-outline-primary"
(click)=
"getCity(userInput.value)"
>
Search
</button>
</div>
</div>
<h2>
Weather in {{weather.name}}, {{weather.sys.country}}
</h2>
</div>
</div>
<div
class=
"col-sm-12 text-center"
>
<span
class=
"temp"
>
{{weather.main.temp|number:'1.0-0'}}
°
F
</span>
<p
class=
"text-uppercase font-italic font-weight-bold"
>
{{weather.weather[0].description}}
</p>
<div
*ngFor=
"let city of cities"
>
<h2
class=
"text-center"
>
Weather in {{city.name}}, {{city.sys.country}}
</h2>
<div
class=
"col-sm-12 text-center"
>
<span
class=
"temp"
>
{{city.main.temp|number:'1.0-0'}}
°
F
</span>
<p
class=
"text-uppercase font-italic font-weight-bold"
>
{{city.weather[0].description}}
</p>
</div>
<table
class=
"table table-light table-striped table-bordered table-sm text-center"
style=
"width: 70%; margin-left: 13%;"
>
<tbody>
<tr>
<td>
Humidity
</td>
<td>
{{city.main.humidity}}%
</td>
</tr>
<tr>
<td>
Pressure
</td>
<td>
{{city.main.pressure}} hPa
</td>
</tr>
<tr>
<td>
Sunrise
</td>
<td>
{{city.sys.sunrise*1000 | date: 'H:mm'}}
</td>
</tr>
<tr>
<td>
Sunset
</td>
<td>
{{city.sys.sunset*1000|date: 'H:mm'}}
</td>
</tr>
</tbody>
</table>
</div>
<table
class=
"table table-light table-striped table-bordered table-sm text-center"
style=
"width: 70%; margin-left: 13%;"
>
<tbody>
<tr>
<td>
Humidity
</td><td>
{{weather.main.humidity}}%
</td>
</tr>
<tr>
<td>
Pressure
</td><td>
{{weather.main.pressure}} hPa
</td>
</tr>
<tr>
<td>
Sunrise
</td><td>
{{weather.sys.sunrise*1000 | date: 'H:mm'}}
</td>
</tr>
<tr>
<td>
Sunset
</td><td>
{{weather.sys.sunset*1000|date: 'H:mm'}}
</td>
</tr>
</tbody>
</table>
</div>
\ No newline at end of file
src/app/today/today.component.ts
View file @
2b300ce5
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Component
,
Input
,
OnInit
}
from
'
@angular/core
'
;
import
{
WeatherService
}
from
'
../weather.service
'
;
@
Component
({
...
...
@@ -7,6 +7,7 @@ import { WeatherService } from '../weather.service';
styleUrls
:
[
'
./today.component.css
'
]
})
export
class
TodayComponent
implements
OnInit
{
@
Input
()
cities
:
any
[];
lat
;
lon
;
weather
;
...
...
@@ -23,6 +24,8 @@ export class TodayComponent implements OnInit {
this
.
weatherService
.
getWeatherDataByCoords
(
this
.
lat
,
this
.
lon
).
subscribe
(
data
=>
{
this
.
weather
=
data
;
if
(
this
.
cities
.
findIndex
(
element
=>
element
.
name
===
this
.
weather
.
name
)
==-
1
)
this
.
cities
.
push
(
data
);
console
.
log
(
this
.
weather
);
}
)
...
...
@@ -32,10 +35,13 @@ export class TodayComponent implements OnInit {
}
getCity
(
city
)
{
this
.
weatherService
.
getWeatherDataByCityName
(
city
).
subscribe
(
data
=>
{
this
.
weather
=
data
;
console
.
log
(
this
.
weather
);
if
(
this
.
cities
.
findIndex
(
element
=>
element
.
name
===
this
.
weather
.
name
)
==-
1
)
this
.
cities
.
push
(
data
);
}
)
}
...
...
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