一款查询天气的WebApp
一、WebApp介绍
1.初始界面
2.搜索结果页面
二、项目代码
1.项目目录
--------app
----------app.component.ts
----------app.component.css
----------app.component.html
----------app.module.ts
2.app.component.html
<div class="content">
<div>
<img width="300" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>{{title}}</h2>
<div>
<form class="form-inline">
<div class="form-group">
<label for="exampleInput">Address</label>
<input type="text" class="form-control" id="exampleInput" placeholder="Please input the address" name="searchAddress">
</div>
<button type="button" class="btn btn-default" (click)="start()">Search</button>
</form>
</div>
</div>
<div class="data" *ngIf="begin">
<table class="table table-striped">
<thead>
<tr>
<th>日期</th>
<th>天气</th>
<th>日间温度</th>
<th>夜间温度</th>
<th>气压值</th>
<th>湿度</th>
<th>天气情况</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let DL of DataList;let i=index;">
<td>{{dateString[i]}}</td>
<td>{{DL.weather[0].main}}</td>
<td>{{DL.temp.day}}</td>
<td>{{DL.temp.night}}</td>
<td>{{DL.pressure}}</td>
<td>{{DL.humidity}}</td>
<td><img src="http://openweathermap.org/img/w/{{DL.weather[0].icon}}.png"/></td>
</tr>
</tbody>
</table>
</div>
3.app.component.ts
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import 'rxjs/add/operator/toPromise'; @Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent{
title = 'A weather search App!';
public http;
Data:any;
begin=false;//控制天气结果列表是否出现
searchAddress:string;//查询框文本的变量声明
dateString:string[];//天气结果列表的七个日期数组声明
DataList:any;//获取到的数据列表变量声明
constructor(private Http:HttpClient) {
this.http = Http;
}
now=new Date()//获取当前时间
GetDateStr(AddDayCount :number) {
this.now.setDate(this.now.getDate()+AddDayCount);//获取AddDayCount天后的日期
let y = this.now.getFullYear();
let m = this.now.getMonth()+1;//获取当前月份的日期
let d = this.now.getDate();
return y+"年"+m+"月"+d+"日";
}
ngOnInit() {//在组件加载进来的时候就执行
this.dateString=[this.GetDateStr(0),this.GetDateStr(1),this.GetDateStr(2),this.GetDateStr(3),this.GetDateStr(4),this.GetDateStr(5),this.GetDateStr(6)]
}
start(){//点击查询之后执行的函数
this.searchAddress = (document.getElementsByName('searchAddress')[0] as HTMLInputElement).value;//获取搜索框里面的文本
if(this.searchAddress.length!=0){//如果搜索框里面的文本不为空,那么结果列表出现,并且发送请求
this.begin=true;
this.http.get("http://api.openweathermap.org/data/2.5/forecast/daily?q="+this.searchAddress+"&mode=json&units=metric&cnt=7&appid=f12159c1f548ea9ab7b5ff1907b1df50")
.subscribe((data) => {
this.Data=data;
this.DataList=this.Data.list;
},
err => { });
}else{//如果搜索框里面的文本为空,那么结果列表不出现,并且不发送请求
alert("请输入地址");
}
}
}
4.app.component.css
.content{
width: 340px;
margin: 0 auto;
}
.data{
width: 800px;
margin: 0 auto;
margin-top: 10px;
}
ps:项目中的数据接口亲测可用,大家可以玩玩
项目代码地址https://github.com/Nangxif/WeatherWebApp
一款查询天气的WebApp的更多相关文章
- 【Python3爬虫】自动查询天气并实现语音播报
一.写在前面 之前写过一篇用Python发送天气预报邮件的博客,但是因为要手动输入城市名称,还要打开邮箱才能知道天气情况,这也太麻烦了.于是乎,有了这一篇博客,这次我要做的就是用Python获取本机I ...
- BAE+Python+Django+Wechatpy+Baidu weather api +微信订阅号 = 实现微信查询天气
最近想在微信上面实现天气查询,分两个步骤: 1.被动回复:输入天气.xx天气获取天气情况 2.主动推送:每天定时推送天气(针对24小时内产生交互的人) 目前已经实现第一个步骤,如下: 现将实现此功能环 ...
- TP5结合聚合数据API查询天气
php根据城市查询天气情况看到有人分享java的查询全国天气情况的代码,于是我想分享一个php版本的查询天气接口.免费查询天气的接口有很多,比如百度的apistore的天气api接口,我本来想采用这个 ...
- python 基础例子 双色球 查询天气 查询电话
# 随机生成双色球import random# 随机数 1-16之间# r = random.randint(1,16)# print(r)phone_numbers_str = "匪警[1 ...
- python+tkinter+动画图片+爬虫(查询天气)的GUI图形界面设计
1.完整代码: import time import urllib.request #发送网络请求,获取数据 import gzip #压缩和解压缩模块 import json #解析获得的数据 fr ...
- 通过Azure bot framework composer 设计一个AI对话机器人bot(查询天气)
本文介绍通过机器人框架设计器 (Bot framework composer)接近拖拉拽的方式设计一个聊天机器人,该聊天机器人的主要功能是发起http请求查询天气.当然,稍微变通下,可以用来查询几乎任 ...
- 原生js实现查询天气的小应用
demo:https://zsqosos.github.io/weather/ 截图: 实现功能:打开网页时显示用户所在城市的天气状况,在输入框输入城市可查询其它城市. 实现过程:先调用百度地图的AP ...
- (转)3款优秀的移动webAPP网站在线测试工具
原文:原文地址 目前适配各个终端的需求越来越强烈呢?比如我们APP项目上线之后,需要一个宣传推广专题页,这个页面当然最好是采取响应式布局来完成.因为需要来推广和下载我们的APP. 无论用户是电脑打开, ...
- Jmeter实例计划(查询天气)
查询计划(天气查询) 这是一个入门计划,仅使用jmeter进行查询功能的计划,可参考http://www.cnblogs.com/TankXiao/p/4045439.html有代码可下载.不过我还是 ...
随机推荐
- CF 303C——Minimum Modular——————【剪枝】
Minimum Modular time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【Spring Cloud】与Spring Boot版本匹配关系
Spring Cloud版本演进情况如下: 版本名称 版本Finchley snapshot版Edgware snapshot版Dalston SR1 当前最新稳定版本Camden SR7 稳定版本B ...
- synchronized修饰普通方法和静态方法
首先,要知道,synchronized关键字修饰普通方法时,获得的锁是对象锁,也就是this.而修饰静态方法时,锁是类锁,也就是类名.class. synchronized修饰普通方法 Synchro ...
- 深入理解读写锁—ReadWriteLock源码分析
转载:https://blog.csdn.net/qq_19431333/article/details/70568478 ReadWriteLock管理一组锁,一个是只读的锁,一个是写锁.读锁可以在 ...
- Python爬虫《Python网络爬虫相关基础概念》
引入 之前在授课过程中,好多同学都问过我这样的一个问题:为什么要学习爬虫,学习爬虫能够为我们以后的发展带来那些好处?其实学习爬虫的原因和为我们以后发展带来的好处都是显而易见的,无论是从实际的应用还是从 ...
- CSS快速入门
一.概述 层叠样式表;可以对HTML的元素,进行控制,使HTML的元素展现的效果和位置更好; 二.基本语法 css规则由两个部分构成:选择器和语句 语句规则: 1.css选择器的名称区分大小写;属性名 ...
- SharePoint 2013 - Using Web Proxy
用于在SharePoint中调用其它网站服务时使用. 1. 需要引用sp.js 和 sp.runtime.js文件: 2. 需要用到SP.WebRequestInfo,SP.WebProxy,和SP. ...
- 【起航计划 031】2015 起航计划 Android APIDemo的魔鬼步伐 30 App->Preferences->Advanced preferences 自定义preference OnPreferenceChangeListener
前篇文章Android ApiDemo示例解析(31):App->Preferences->Launching preferences 中用到了Advanced preferences 中 ...
- attention机制的实现
本文转自,http://www.jeyzhang.com/understand-attention-in-rnn.html,感谢分享! LSTM 中实现attention:https://distil ...
- php json_encode 中文乱码解决方法
本文列举3个方法,实现json_encode()后的string显示中文问题. 做接口时不需要,但存log时帮了大忙了. 在贴代码前,必须贴上官方param和return,链接:http://php. ...