My code in service is:
getUserdata(id:string): Observable<any> {
    return this.http.get('https://jsonplaceholder.typicode.com/todos/' + id)
        .map((res: Response) => {
            const data = res.json();
            return data;
        })
}
And in my component is:
ngOnInit() {
    this.serveicService.getUserdata('1').subscribe(res => {
        this.title = res.title; 
        console.log(this.title); // prints value   
    });
    console.log(this.title); // prints undefined 
}
I need to get data outside of the subscribe method.
 
     
    