import { forkJoin } from 'rxjs' ; import { Component , ViewEncapsulation , OnInit } from '@angular/core' ; import { ModalController , NavParams } from '@ionic/angular' ; import { SearchImageService } from '@services/search-image/search-image-service' ; import { LoaderService } from '@services/loader/loader.service' ; @ Component ( { selector : 'app-show-actors-modal' , templateUrl : 'show.actors.modal.html' , styleUrls : [ './show.actors.modal.scss' ] , encapsulation : ViewEncapsulation . None } ) export class ShowActorsModalComponent implements OnInit { actors : any = [ ] ; constructor ( private modalCtrl , private navParams , private searchImageService , private loaderService ) { console . log ( 'ShowActorsModalComponent::constructor | method called' ) ; } ngOnInit ( ) { console . log ( 'ShowActorsModalComponent::ngOnInit | method called' ) ; this . loaderService . present ( 'Please wait, loading actors...' ) ; let actors = this . navParams . data . modalProps . actors ; actors = actors . split ( ',' ) ; forkJoin ( actors . map ( actor => { return this . searchImageService . searchImage ( actor ) ; } ) ) . subscribe ( results => { if ( results . length > 0 ) { results . map ( ( result , index ) => { this . actors . push ( { name : actors [ index ] , image : result [ 'items' ] [ 0 ] . image . thumbnailLink } ) ; } ) ; this . loaderService . dismiss ( ) ; } } ) ; } dismiss ( ) { this . modalCtrl . dismiss ( ) ; } }