I'm trying to retrieve data from and endpoint in Angular. This is the service:
export class VideosService {
result;
constructor(private http: Http, public router: Router) { }
getVideos() {
this.http.get('http://localhost:3000/videos?sessionId=' + localStorage.getItem('sessionId'))
.map(response => response.json())
.subscribe(result => this.result = result);
localStorage.setItem('videos', this.result);
console.log(localStorage);
}
It works everytime EXCEPT the first one. The first one I've got "undefined" and the other one's I get the actual object.
What I'm doing wrong? Thnks!