fengxiang
2018-07-12 4b35f9a98f9431e17fc96d998c7cc9021776787b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Component, OnInit } from "@angular/core";
import { _HttpClient } from "@delon/theme";
import { zip } from 'rxjs/observable/zip';
 
@Component({
  selector: "app-home-page",
  templateUrl: "./home-page.component.html",
  styleUrls: ["./home-page.component.less"]
})
export class HomePageComponent implements OnInit {
  public cardData: {'api'?:number,'temperature'?:number,'windDirection'?: string,'pm25'?: number}
          = {};
  constructor(
    private http:_HttpClient,
  ) {
  }
 
  ngOnInit() {
    zip(
       this.http.get('http://sapi.7drlb.com/api/mj?cityID=1102&apiKey=condition'),
       this.http.get('http://sapi.7drlb.com/api/mj?cityID=1102&apiKey=aqi')
 
     ).subscribe(
        ([conRes,aqiRes]) => {
          console.log(conRes);
          console.log(aqiRes);
          if( conRes.code == 0 && aqiRes.code == 0 ) {
            this.cardData.windDirection =conRes.data.condition.windDir;
            this.cardData.temperature =conRes.data.condition.temp;
            this.cardData.api = aqiRes.data.aqi.value;
            this.cardData.pm25 = aqiRes.data.aqi.pm25;
          }
        }
     )
  }
}