0
export class AppComponent implements OnInit {

  movieList: Observable<any>;
  constructor(private AppService:AppService){

  }
  ngOnInit() {
      this.getMovies();
  }

  getMovies() {

    this.movieList = this.AppService.getMovies().map(movie => {
      return {
        name: movie.name
      }
    });


  this.movieList.subscribe(data => {
    debugger;
  })
  }
}

I want to perform Rxjs operations on observable this.movieList but Data in debugger returns undefined when i subscribe to this.movieList

1 Answers1

0

Problem is your getMovies returns a collection and in the map you are considering it as a single item. If you chage to this it should wotk

this.movieList = this.AppService.getMovies().map(movies => movies.map(movie => { return { name: movie.name } }));
Deepak Sharma
  • 1,873
  • 10
  • 23