我有report.service.ts
一个简单的方法来获取reports
(它只是一个来自模拟的报表对象的 const 数组),它真正做的是:
@Injectable()
export class ReportService {
getReports() {
var ret = Observable.create(function(observer){ observer.onComplete(REPORTS) });
return ret;
}
}
现在在我的app.component
我想得到那些报告。所以我做了:
@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()
}
}
就是这样,但它不起作用,显然我在这里做错了,我是可观察的新手:/
谢谢!