src/app/app.component.ts
The main AppComponent in which the app bootstraps
providers |
WeatherService
|
selector | app-root |
styleUrls | app.component.scss |
templateUrl | ./app.component.html |
Properties |
Methods |
constructor(_weatherService_: WeatherService)
|
||||||||
Defined in src/app/app.component.ts:24
|
||||||||
Creates an instance of AppComponent.
Parameters :
|
getWeather |
getWeather()
|
Defined in src/app/app.component.ts:42
|
Call weatherforecast api using injectable service
Returns :
void
|
ngOnInit |
ngOnInit()
|
Defined in src/app/app.component.ts:35
|
Initialize component
Returns :
void
|
errorMessage |
errorMessage:
|
Type : any
|
Defined in src/app/app.component.ts:24
|
Error message for api callback |
weatherForecastData |
weatherForecastData:
|
Type : string[]
|
Defined in src/app/app.component.ts:18
|
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>