AngularJS获取天气预报(案例)

来源:互联网 发布:php 文件名截断 编辑:程序博客网 时间:2024/06/07 14:28
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>天气预报</title></head><body ng-app="Weather"><div ng-controller="WeatherController"><table><tr ng-repeat="weather in weatherData"><td>{{weather.date}}</td><td>{{weather.temperature}}</td><td>{{weather.weather}}</td><td>{{weather.wind}}</td><td><img ng-src="{{weather.dayPictureUrl}}" alt=""></td><td><img ng-src="{{weather.nightPictureUrl}}" alt=""></td></tr></table></div><script src="./libs/angular.min.js"></script><script>var Weather = angular.module('Weather', []);Weather.controller('WeatherController', ['$scope', '$http', function ($scope, $http) {$http({url: 'http://api.map.baidu.com/telematics/v3/weather',method: 'jsonp',params: {location: '北京',output: 'json',ak: '0A5bc3c4fb543c8f9bc54b77bc155724',//这两个ak用不了了需要自己取下载callback: 'JSON_CALLBACK'}}).success(function (info) {// console.log(info);$scope.weatherData = info.results[0].weather_data;});}]);</script></body></html>

0 0
原创粉丝点击