我有一个现有的角2项目,我把它移植到了角6,现在我的HTTP可观测性不再运行了。据我所知,这是关于新观察到的不同操作的。
我的服务还可以观察到。这是我在组件中订阅并设置interval和startindex的。
我怎样才能在第六角做到这一点?
// SERVICE
@Injectable ()
export class ViewService
{
constructor (private http : HttpClient)
{ }
foo () : Observable <any>
{
return this.http.get ("http://blabla",
{responseType: "json"});
}
}
// COMPONENT
export class ViewComponent
{
constructor (private vs : ViewService)
{ }
ngOnInit ()
{
this.vs.foo ().interval (1000).startWith (0).subscribe (
(resp) =>
{
});
}
}误差
错误:错误TS2339:属性‘间隔’在类型‘可观察’上不存在
使用rxjs 6.0.0
发布于 2018-07-21 08:12:08
首先,您必须从interval中导入rxjs。
import { interval } from 'rxjs';导入startWith,还必须从rxjs/operators导入mergeMap。
import { startWith, mergeMap } from 'rxjs/operators';然后你可以像这样使用它们:
interval(1000).pipe(
startWith(0),
mergeMap(iRes => this.vs.foo())).subscribe(resp => {
console.log(resp);
});希望这能帮到你!
发布于 2018-07-21 10:01:21
RxJS v6中有几处变化是Angular6采用的,您需要注意:
如果您仍然感到困惑,请看Ben Lesh的视频,并了解RxJS v6:https://www.youtube.com/watch?v=JCXZhe6KsxQ中发生了哪些变化。
https://stackoverflow.com/questions/51453858
复制相似问题