I have problem with understanding of async angular http client. I had backend part written in Java where endpoints return data with the same format but different meaning. So I decided to create follow code:
export class AppComponent implements OnInit{
temperatureDailyCharts: Chart[] = new Array();
constructor(private weatherService: WeatherService){}
ngOnInit(): void {
this.getDailyParameterCharts("temperature", this.temperatureDailyCharts);
}
getDailyParameterCharts(parameter: string, chartList: Chart[]) {
this.weatherService.getDailyParameter(1, parameter)
.subscribe(response => chartList = response);
}
}
Next step is injecting this.temperatureDailyCharts[0]
to child component, and waiting for ngOnChange
. This code doesn't work correctly, because ngOnChanges
method will never invoke. If I change my subscribe part to explicity sign value
.subscribe(response => this.temperatureDailyCharts = response);
it is ok. Please, explain me why this (from my point of view both codes are the same) construction is bad?