0

I have a report.service.ts that have one simple method to get reports (which is just a const array of reports object from a mock), and all it really does is this:

@Injectable()
export class ReportService {
  getReports() {
    var ret = Observable.create(function(observer){ observer.onComplete(REPORTS) });
    return ret;
  }
}

now in my app.component I want to get those reports. So I did:

@Component({
  selector: 'workPrioritizer-reports',
  styles: [require('./app.css')],
  template: require('./app.component.html'),
})

export class ReportsCmp implements OnInit{
  reports: Report[];
  title = 'Reorder List';

  constructor(private reportService: ReportService) {}

  getReports() {
    var sub = this.reportService.getReports().subscribe(function(x){return x});
    return sub;
  }

  ngOnInit() {
    this.getReports()
  }
}

this is it, but its not working, obviously im doing something wrong here, im new to observables :/

thanks!

jack miao
  • 1,398
  • 1
  • 16
  • 32

1 Answers1

0

in your Observable.create you need to use observer.next(REPORTS).

also if you want to to invoke the complete function, you will have to change it to observer.complete().

Doron Brikman
  • 2,444
  • 1
  • 16
  • 17