I have a subscription on an object that comes in. I'm trying to get one property of that object - publishedOn but keep running into problems with it Cannot read property 'publishedOn' of undefined in the console.
This is my subscription:
 ngOnInit() {
    //Get the source from the source display panel
    this.subscription = this.sourceDisplayService.currentSource.subscribe(source => this.source = source);
    this.compareDates(this.source);
My date comparison method:
 compareDates(source){
    let context;
    let dateP = this.source;
    console.log(source.publishedOn);
    let publishedDate = new Date(dateP.publishedOn); 
     if (this.source.publishedOn <= this.electionDate) {
        let context = "Pre-election";
     } else {
        let context = "Post-election";
     }
     console.log(context);
     return context;
  }
 
    