File

src/app/app.component.ts

Description

The main AppComponent in which the app bootstraps

Implements

OnInit

Metadata

providers WeatherService
selector app-root
styleUrls app.component.scss
templateUrl ./app.component.html

Index

Properties
Methods

Constructor

constructor(_weatherService_: WeatherService)

Creates an instance of AppComponent.

Parameters :
Name Type Optional Description
_weatherService_ WeatherService

weatherservice injectable

Methods

getWeather
getWeather()

Call weatherforecast api using injectable service

Returns : void
ngOnInit
ngOnInit()

Initialize component

Returns : void

Properties

errorMessage
errorMessage: any
Type : any

Error message for api callback

weatherForecastData
weatherForecastData: string[]
Type : string[]

weather forecast data

import { WeatherService } from './weather/weather.service';
import { Component, OnInit } from '@angular/core';

/**
 * The main AppComponent in which the app bootstraps
 */
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  providers: [WeatherService]
})
export class AppComponent implements OnInit {
  /**
   * weather forecast data
   * @type {string[]}
   */
  weatherForecastData: string[];

  /**
   * Error message for api callback
   * @type {*}
   */
  errorMessage: any;

  /**
   * Creates an instance of AppComponent.
   * @param {WeatherService} _weatherService_ weatherservice injectable
   */
  constructor(private _weatherService_: WeatherService) {}

  /**
   * Initialize component
   */
  ngOnInit() {
    this.getWeather();
  }

  /**
   * Call weatherforecast api using injectable service
   */
  getWeather() {
    this._weatherService_.getWeatherForecast().subscribe(
      data => {
        this.weatherForecastData = data;
      },
      err => {
        this.errorMessage = <any>err;
      }
    );
  }
}
<div class="container-fluid">
  <app-header></app-header>
  <div class="row">
    <div class="col-md-12">
      <app-weather-list [weathers]="weatherForecastData"></app-weather-list>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""