I want to change all of my EventEmitter to Subjects since it is the recommended way to share variables and states instead of emitting an event.
But now I've got a problem and I just don't understand how to solve it. Here is the sample code:
@Injectable()
export class TicketsService implements OnInit {
private _url = "http://127.0.0.1:3000/api/getAllTickets";
private _refreshTickets:Subject<JSON> = new Subject<JSON>();
public allTickets:JSON;
private _url_postNewTicket = "http://127.0.0.1:3000/api/postNewTicket";
constructor(private _http:AuthHttp) {
this.allTickets = this._refreshTickets
.mergeMap(() => this._http.get(this._url))
.map((res:Response) => res.json())
.cache();
}
refreshAllTickets() {
console.log("refresh all tickets..");
this._refreshTickets.next(null);
}
}
The compiler gives me the following error:
public/angular/app/tickets.service.ts(26,9): error TS2322: Type 'Observable' is not assignable to type 'JSON'. [1] Property 'parse' is missing in type 'Observable'.
I guess I could write allTickets:JSON
as allTickets:any
but in the component I use ngFor to iterate - so I get the error from ngFor that it needs an array.
Thanks in advance!