import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
@Injectable()
export class RestProvider {
baseUrl:string = "https://localhost.local/api/v1";
constructor(private httpClient: HttpClient) {}
//Get latest events from API
public getEvents(): Observable<Event[]> {
return this.httpClient
.get(this.baseUrl + '/events')
.map(events => {
return events.map((event) => new Event(event));
})
.catch((err)=>{
console.error(err);
return Observable.throw(err);
});
}
public getEventById(eventId: number): Observable<Event> {
return this.httpClient
.get(this.baseUrl + '/events/' + eventId)
.map(response => {
return new Event(response);
})
.catch((err)=>{
console.error(err);
return Observable.throw(err);
});
}
}
export class Event {
id: number;
calendar_id: number;
title: string;
slug: string;
excerpt: string;
content: string;
multidate: string;
allday: number;
grouped: number;
event_gty: number;
event_price: number;
location_name: string;
location_address: string;
contact_email: string;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
return events.map((event) => new Event(event));
map has a TS error "Property ‘map’ does not exist on type ‘object’.
I’m sure this is a complete newb question, so any help is greatly appreciated!