Posts

Es werden Posts vom November, 2016 angezeigt.

Angular 2 Observing a Service and find Results

As i do not write so much blog posts, i decided to write some just short snippets for known problems. This covers searching inside Object Array for Angular 2 and Typescript Finding index of an Array Entry with Angular 2 and Typescript Example of how to use Observer able service in Angular 2 //service is Observable this.name = 'nameToFind'; GetGalleryPics(galleryId).subscribe((data:Picture[]) => { //success this.pictures = data; //searching inside the array and find first entry this.picture = this.pictures.filter(pic => pic.name == this.name)[0] console.log(this.picture); //find let pictureIndex = this.pictures.findIndex(pic => pic.name == this.name); console.log('this picture'+pictureIndex); },