I have an angular page which has a list of properties. Each property has a link to view the details of the property. I have a function which maps the property by id, however as a return I am always getting undefined (printed in console).
service.ts
 getProperties(): Observable<IProperty[]>{
     return this.http.get<IProperty>('http://localhost:3000/')
     .do(data => this.properties.push(JSON.stringify(data)))
     .catch(this.handleError);  
 }
 getProperty(id:number): Observable<IProperty>{
    return this.getProperties()
    .map((properties: IProperty[])=> properties.find(p=>p.propertyId===id));
}
propertyDetail.component.ts
import { Component, OnInit } from '@angular/core';
import { IProperty } from './property';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiService} from '../api/api.service';
import { PropertyGuardService } from './property-guard.service' 
@Component
({
  selector: 'propertyDetail',
  templateUrl: './propertyDetail.component.html',
  providers: [PropertyGuardService]
})
export class PropertyDetailComponent implements OnInit
{
    pageTitle:string = "Property Details";
    property: IProperty;
    errorMessage: string ="";
    constructor(private _route : ActivatedRoute,
                private _router: Router,
                private apiService: ApiService){
       console.log(this._route.snapshot.paramMap.get('id'));
    }
    ngOnInit(){
        const param = this._route.snapshot.paramMap.get('id');
        if(param){
            const id = +param;
            this.getProperty(id);
            console.log(this.getProperty(id));
        }            
    }
    getProperty(id:number)
    {
            this.apiService.getProperty(id).subscribe(
            property => this.property = property,
            error => this.errorMessage = <any>error);
    }
    onBack(): void
    {
        this._router.navigate(['/properties']);
    }
}  
 
    