My code is producing the following error:
TS2739 (TS) Type 'Observable<Object>' is missing the following properties from type 'WeatherForecast': ID, date, temperatureC, temperatureF, summary
I'm puzzled as to why this error is occurring since my object contains all the necessary variables. The ApiService I've created includes a WeatherForecast object that does indeed have the specified variables like this.
export class WeatherForecast {
ID: number
date: number
temperatureC: number
temperatureF: number
summary: string
}
This component file was created for editing the weather forecast table.
export class EditWeatherForecastComponent implements OnInit {
title = 'Edit Data';
baseUrl: string;
ID: number;
forecast: WeatherForecast = {
ID: 0,
date: 0,
temperatureC: 0,
temperatureF: 0,
summary: ''
};
constructor(private service: ApiService, @Inject('BASE_URL') baseUrl: string, private formBuilder: FormBuilder, public http: HttpClient, private router: ActivatedRoute) {
this.baseUrl = "https://localhost:44347/WeatherForecast";
}
forecasts: any = [];
ngOnInit(): void {
this.refreshWeatherList();
this.ID = +this.router.snapshot.paramMap.get('ID');
this.forecast = this.service.getWeatherListID(this.ID); //ERROR HERE
}
refreshWeatherList() {
this.service.getForecast().subscribe(data => {
this.forecasts = data;
});
}
onSubmit(form: NgForm) {
let forecasts: WeatherForecast = {
ID: form.value.id,
date: form.value.id,
temperatureC: form.value.id,
temperatureF: form.value.id,
summary: form.value.id
}
}
}
Here's the service
getWeatherListID(ID: number) {
return this.http.get(this.baseURL + '/?ID=' + ID)
}