在役
this._ProductUrl =".../api/products"
getProduct(): Observable <IProduct[]>{
return this._http.get(this._ProductUrl)
.map((response:Response) => <IProduct[]> response.json())
.catch(this.handleError);
}
app.component.ts
间隔不工作
Observable
.interval(2*60*1000)
.timeInterval()
.flatMap((this._productService.getProduct())
.subscribe((response) => {
}),(err)=> {this.errorMsg =<any>err};
将鼠标悬停在该行上时会显示一些错误。此行中的错误:
Argument of type '(err: TimeInterval<number>) => void' is not assignable to parameter of type '(value: TimeInterval<number>, index: number) => ObservableInput<{}>'.
Type 'void' is not assignable to type 'ObservableInput<{}>'
当这样尝试时
Observable
.interval(2*60*1000)
.timeInterval()
.flatMap((this._productService.getProduct(response))).subscribe((response) => {
}),(err)=> {this.errorMsg =<any>err};
此行错误:
.flatMap((this._productService.getProduct(response)
[ts] Expected 0 arguments, but got 1.
(property) AppComponent._productService: ProductServic
e
没有间隔工作正常
this._productService.getProduct().subscribe((response) => {
console.log(error);
}),(err)=> {this.errorMsg =<any>err};
以上代码存在语法问题,请提供更好的解决方案,不胜感激