一款查询天气的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有代码可下载.不过我还是 ...
随机推荐
- 获取全球dns统计信息
# -*- coding:UTF-8 -*- import requests, time import json from bs4 import BeautifulSoup as bp t3 = ti ...
- 浅谈前端与SEO
转载地址: https://blog.csdn.net/lzm18064126848/article/details/53385274?tdsourcetag=s_pctim_aiomsg SEO(S ...
- java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ 解决方案
//第一个异常 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysq ...
- mysql的引擎和锁
- 洛谷P2312 解方程(暴力)
题意 题目链接 Sol 出这种题会被婊死的吧... 首先不难想到暴力判断,然后发现连读入都是个问题. 对于\(a[i]\)取模之后再判断就行了.注意判断可能会出现误差,可以多找几个模数 #includ ...
- twaver拓扑图通道组织图(百分比使用率/水槽)效果实现
功能介绍: 利用拓扑图实现:64条通道,根据每条通道是否承载业务,提供百分比展示 首先上图,功能效果如图: 废话不多,直接上代码: <!DOCTYPE html> <html> ...
- SharePoint 2013 - Designer Workflow
另一篇文章 SharePoint Designer - Workflow 1. 可以定义每个Stage的名称,并将Stage名称显示在工作流状态字段,相比于SP2010时仅有的in progress ...
- CentOS安装chrome-浏览器
首先,在CentOS中安装软件,通过yum命令来安装软件,就要在系统中的软件源中添加软件源节点,即在目录./etc/yum.repos.d/下的CentOS-Base.repo文件中做修改:在控制台C ...
- jquery mobile 自定义图标
Jquery Mobile框架包含了一组最常用的移动应用程序所需的图标,为了减少下载的大小,Jquery Mobile包含的是的白色的图标sprite图片,并自动在图标后添加一个半透明的黑圈以确保在任 ...
- ASP.NET MVC4 with MySQL: Configuration Error (MySql.Web.v20)
今天在浏览ASP.NET项目时,提示如下错误: Could not load file or assembly ‘MySql.Web.v20, Version=6.9.4.0, Culture=neu ...