неявный контекст не определен, угловой 7 - PullRequest
0 голосов
/ 20 февраля 2019

Правильно, поэтому я перебираю массив информации, и эта информация показывает то, что мне нужно, однако я получаю несколько удивительных ошибок в моей консоли: ERROR TypeError: "_v.context.$implicit is undefined"

apiservice:

private extractData(res: Response) {
    let body = res;
    return body || {};
  }

  getWeather(city: string, isoCode: string): Observable<any> {
    return this.http.get(`${this.endPoint}${city},${isoCode}${this.constants.apiKey}`)
    .pipe(map(this.extractData));
  }

компонент, использующий API-сервис:

  theWeather:any = [];
  countryList = COUNTRIES;
  isLoading: boolean = true;
  showWeather: boolean = false;

  constructor(private apiCall:ApiService) { }


  ngOnInit() {
    this.retrieveWeather()
  };

  retrieveWeather() {
    console.log('COUNTRY LIST', this.countryList);

    this.theWeather = [];
    this.countryList.map((element, i) => {
      this.apiCall.getWeather(element.city, element.countryIso)
        .subscribe((data: {}) => {
          element.weatherInfo = data;
        });
        this.isLoading = false;
      });
      this.showWeather = true;
  };

и html-файл:

<div class="country-container">
  <div *ngIf="isLoading">
    <mat-card>
      <mat-progress-spinner class="spinner-style" color="primary" mode="indeterminate"></mat-progress-spinner>
    </mat-card>
  </div>
  <div *ngIf="showWeather" class="card-container">
    <mat-card *ngFor="let c of countryList" class="card">
      <mat-card-title>Weather for: {{c.city}}, {{c.countryName}}</mat-card-title>
      <mat-card-content>The current weather is: {{c.weatherInfo.weather[0].description}}</mat-card-content>
    </mat-card>

  </div>
</div>

наконец образ моей консоли: enter image description here

Спасибо за помощь!

edit: сделал заголовок более конкретным для вопроса.

1 Ответ

0 голосов
/ 20 февраля 2019

по моему мнению на 5-м элементе (в строке 10 указатель 4 (который является 5-м элементом)) в списке не удается получить погодные условия ... проверьте параметры запроса и / или неверные данные возврата.удалите временный элемент или проверьте его, чтобы увидеть, «ли ошибка».может быть, лучше всего проверить неопределенность, даже если нет ошибки http.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...