LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code


  
  
  
  聚合数据天气应用


  

天气应用

{{Data.today.city}}

{{Data.today.week}}

{{Data.today.date_y}}


今天天气

{{Data.today.weather}}

{{Data.today.temperature}}

湿度:{{Data.sk.humidity}}

{{Data.today.wind}}

穿衣指数:{{Data.today.dressing_index}}

洗车指数:{{Data.today.wash_index}}

旅行指数:{{Data.today.travel_index}}

锻炼指数:{{Data.today.exercise_index}}

紫外线指数:{{Data.today.uv_index}}


未来6天天气

{{item.week}}

{{item.temperature}}

{{item.weather}}

{{item.wind}}

CSS
img{margin:0 auto;}
    a{display: inline-block;}
    h1{display: inline-block;vertical-align: 8px;color: orange;}
JS
var app = angular.module('Weather', []);
app.factory('WeatherApi', function($http) {
  var obj = {};
  obj.getIP  = function() {
    return $http.jsonp("http://ipinfo.io/json?callback=JSON_CALLBACK");
  }
  obj.getCurrent = function(ip) {
    var api = "http://v.juhe.cn/weather/ip?format=1";
    var APPKey = "&key=dd0765af20d40a69cd17b8d0b1fb7aec&ip=";
    var cb = "&callback=JSON_CALLBACK";
    return $http.jsonp(api + APPKey + ip + cb);
  };
  return obj
});

app.controller('MainCtrl', function($scope, WeatherApi) {
  $scope.Data = {};
  WeatherApi.getIP().success(function(data){
    var ip = data.ip;
    WeatherApi.getCurrent(ip).success(function(data) {
      $scope.Data = data.result;
      $scope.items= data.result.future;
      delete $scope.items[Object.keys($scope.items)[0]];
    });
  })
});
Host Instantly Drag and Drop Website Builder

 

Term
Mon, 11/27/2017 - 21:42

Related Codes

Pen ID
Pen ID
Pen ID