mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
24 lines
608 B
TypeScript
24 lines
608 B
TypeScript
import * as ko from 'knockout';
|
|
import 'isomorphic-fetch';
|
|
|
|
interface WeatherForecast {
|
|
dateFormatted: string;
|
|
temperatureC: number;
|
|
temperatureF: number;
|
|
summary: string;
|
|
}
|
|
|
|
class FetchDataViewModel {
|
|
public forecasts = ko.observableArray<WeatherForecast>();
|
|
|
|
constructor() {
|
|
fetch('api/SampleData/WeatherForecasts')
|
|
.then(response => response.json() as Promise<WeatherForecast[]>)
|
|
.then(data => {
|
|
this.forecasts(data);
|
|
});
|
|
}
|
|
}
|
|
|
|
export default { viewModel: FetchDataViewModel, template: require('./fetch-data.html') };
|