I don't understand why this service doesn't work? Is it some problem with dependencies?
service:
import { Http } from '@angular/http'; export class GetWeatherService { constructor(private http: Http) {} getWeather() { return this.http.get(link); } } and component:
import { Component, OnInit } from '@angular/core'; import { GetWeatherService } from './get-weather.service'; @Component({ selector: 'app-form', templateUrl: './form.component.html', styleUrls: ['./form.component.css'], providers: [GetWeatherService] }) export class FormComponent implements OnInit { constructor(public getWeather: GetWeatherService) {} ngOnInit() { this.getWeather.getWeather(); } }