I have a service to share the variables among the components as follows,
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class AppMessageQueuService {
checkOutPageParams: Subject<Object>;
constructor() {
this.checkOutPageParams = new Subject<string>();
}
}
I use this service to pass the following parameters to another component,
this.appMsgService.checkOutPageParams.next({
'userId': listItem.userInfo.userId,
'listingId': listItem.listingId,
'event': this.event
});
I can see the values being assigned to event when i debug, this is how i get the values in the 2nd component,
this.appMsgService.checkOutPageParams.asObservable()
.switchMap((params: Object) => {
let userId = params['userId'];
let listingId = params['listingId'];
this.event = params['event'];
return this.checkOutInforService.getCheckoutDetails(userId, listingId);
}).subscribe((checkoutDetail: CheckoutUserDetail) => {
this.checkoutInfoDetails = checkoutDetail;
});
console.log(this.event) //this returns undefined
I can see the value being assigned to event as well. but when i print a console.log(this.event) after the above lines, it says undefiend.
What is the issue. how can i assign the value to the event and use it within the component 2.