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);

      },

Kommentare

Beliebte Posts aus diesem Blog

SoCraTes Day Franken 2019

During the final plan review, Program risks are addressed using ROAM. What do the letters in ROAM represent?

Which core competency ot the Lean Enterprise helps drive Bullt-in Quality practices?