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!

4

1 に答える 1

0

Observable.create使用する必要がありますobserver.next(REPORTS)

また、完全な関数を呼び出したい場合は、に変更する必要がありますobserver.complete()

于 2016-07-18T19:20:17.033 に答える