I want to fetch customers
list from my back-end via get
Http
call. But i am unable to declare array
of customers
in my component
.
I have customer.interface.ts like this
export interface Customer {
_id?: string,
name: string,
email: string,
phone?: string,
address?: string,
age?: number
}
I have http.service.ts
get = (url: string): Observable<any> => {
return this.http.get(this.createUrl(url), { headers: this.getHeaders() });
}
In my customer.service.ts
getCustomers(): Observable<Customer[]>{
return this._http.get(ApiConstants.getCustomers);
}
In my customer.component.ts
customers$: Observable<Customer[]> = [];
ngOnInit(){
this.customers$ = this.customerService.getCustomers();
}
Now it's giving me an error on this line customers$: Observable<Customer[]> = []
like this inside editor at compile time.
Type 'never[]' is missing the following properties from type 'Observable<Customer[]>': isScalar, source, operator, lif and 5 more
What's wrong here?