angular-网络请求天气
来源:互联网 发布:天刀男号捏脸数据 编辑:程序博客网 时间:2024/05/22 02:17
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="angular-1.3.0.js"></script>
<title></title>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.value("URL", "https://free-api.heweather.com/v5/weather?city=beijing&key=545d63e185fc48169a43cbabba6e74d2");
app.factory("weather", function ($http, $q, URL) {
return function () {
return $http.get(URL).then(function (response) {
var data = response.data.HeWeather5[0];
var weather = {city: data.basic.city, txt: data.now.cond.txt, day3: [], hour4: []};
for (var i in data.daily_forecast) {
weather.day3.push({
date: data.daily_forecast[i].date,
txt: data.daily_forecast[i].cond.txt_d
});
}
for (var i in data.hourly_forecast) {
weather.hour4.push({
time: data.hourly_forecast[i].date,
txt: data.hourly_forecast[i].cond.txt
});
}
return weather;
}, function (response) {
return $q.reject(response.status);
});
}
});
app.controller("myCtrl", function ($scope, weather) {
weather().then(function (weather) {
$scope.weather = weather;
}, function (status) {
console.log(status);
});
});
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div>
城市:<i>{{ weather.city }}</i>
</div>
<div>
天气:<i>{{ weather.txt }}</i>
</div>
<div>未来3天天气:</div>
<table border="1">
<tr>
<th>日期</th>
<th>天气</th>
</tr>
<tbody ng-repeat="value in weather.day3">
<tr>
<td>{{ value.date }}</td>
<td>{{ value.txt }}</td>
</tr>
</tbody>
</table>
<div>未来几小时天气:</div>
<table border="1">
<tr>
<th>时间</th>
<th>天气</th>
</tr>
<tbody ng-repeat="value in weather.hour4">
<tr>
<td>{{ value.time }}</td>
<td>{{ value.txt }}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="angular-1.3.0.js"></script>
<title></title>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.value("URL", "https://free-api.heweather.com/v5/weather?city=beijing&key=545d63e185fc48169a43cbabba6e74d2");
app.factory("weather", function ($http, $q, URL) {
return function () {
return $http.get(URL).then(function (response) {
var data = response.data.HeWeather5[0];
var weather = {city: data.basic.city, txt: data.now.cond.txt, day3: [], hour4: []};
for (var i in data.daily_forecast) {
weather.day3.push({
date: data.daily_forecast[i].date,
txt: data.daily_forecast[i].cond.txt_d
});
}
for (var i in data.hourly_forecast) {
weather.hour4.push({
time: data.hourly_forecast[i].date,
txt: data.hourly_forecast[i].cond.txt
});
}
return weather;
}, function (response) {
return $q.reject(response.status);
});
}
});
app.controller("myCtrl", function ($scope, weather) {
weather().then(function (weather) {
$scope.weather = weather;
}, function (status) {
console.log(status);
});
});
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div>
城市:<i>{{ weather.city }}</i>
</div>
<div>
天气:<i>{{ weather.txt }}</i>
</div>
<div>未来3天天气:</div>
<table border="1">
<tr>
<th>日期</th>
<th>天气</th>
</tr>
<tbody ng-repeat="value in weather.day3">
<tr>
<td>{{ value.date }}</td>
<td>{{ value.txt }}</td>
</tr>
</tbody>
</table>
<div>未来几小时天气:</div>
<table border="1">
<tr>
<th>时间</th>
<th>天气</th>
</tr>
<tbody ng-repeat="value in weather.hour4">
<tr>
<td>{{ value.time }}</td>
<td>{{ value.txt }}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
阅读全文
0 0
- angular-网络请求天气
- Angular 网络请求404
- 请求天气对话框无限轮播网络请求判断
- 请求天气
- angular.js查询天气
- python网络天气爬虫
- Angular----$http请求数据
- angular post请求方式
- angular-请求数据
- angular 遍历 请求 赋值
- angular实现httpget请求
- 获取网络天气数据---天气小软件
- javascript请求天气API大全
- 跨域请求:查询天气
- Android网络与数据存储03-在线请求天气API,并解析其中的json数据予以显示
- [Android入门]从零构建Android app之天气——5.设计网络请求底层架构
- WebService调用网络查询天气
- angular 路由请求js文件
- 神一样的大腿
- 分布式锁的理解,普通锁为什么解不了分布式同步问题
- LWC 54:696. Count Binary Substrings
- Android控件系列之RadioButton&RadioGroup
- 常用激活函数介绍
- angular-网络请求天气
- 关于Interger和int
- recycleView 瀑布流
- hdu 4734 F(x) 数位DP
- 区间DP 表达式
- [笔记]filter,空字符,0,None都是False应用
- Dubbo之添加到开启自动启动-yellowcong
- BZOJ 2654: tree 最小生成树+二分
- 写struts2遇到的一个小问题