I've a very basic question related to a service. I've this method getAllArticlesFromDb
in my service that will fetch data from an API using HTTP
's GET call. Here is the method:
article.service.ts
getAllArticlesFromDb() : Observable<any> {
return this._httpClient.get('https://obscure-tundra-38074.herokuapp.com/api/articles');
}
I thought I should not use <any>
as I know the structure of the Object that is returned by the API. So I created a model:
article-model.ts
export class Article {
articleid: string | undefined;
title: string | undefined;
content: string | undefined;
date: string | undefined;
contributor: string | undefined;
}
The problem starts here. Why I can't modify my service method like this:
import { Article } from './model/article-model';
getAllArticlesFromDb() : Observable<Article> {
// same GET call
}
I'm getting this error:
"Type 'Observable Object' is not assignable to type 'Observable Article'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'Article': articleid, title, content, date, and 1 more."
Please correct my mistake.