服务代码-
private flgCityMismatch$ = new BehaviorSubject<boolean>(false);
flgCityMismatchVal = this.flgCityMismatch$.asObservable();
setflgCityMismatch(value: boolean) {
this.flgCityMismatch$.next(value);
}
在Component中,我正在调用setflgCityMismatch以根据用户操作来设置值-
showProfileDetailsLink(redirectURl: string) {
this.dataService.setflgCityMismatch(true);
this.router.navigate([redirectURl]);
}
我正在呼叫订阅行为行为主题,如下所示-
this.dataservice_mylocation.flgCityMismatchVal.subscribe(data => flgCityMismatch = data);
分配值后,我想退订。我试过-
let flgCityMismatch = false;
this.dataservice_mylocation.flgCityMismatchVal
.pipe(take(1)) // this is throwing error
.subscribe(data => flgCityMismatch = data);
但是我遇到了错误-
"message": "Argument of type 'Observable<unknown>' is not assignable to parameter of type 'OperatorFunction<boolean, unknown>'.\n Type 'Observable<unknown>' provides no match for the signature '(source: Observable<boolean>): Observable<unknown>'.",
我正在使用Angular8。我不知道这是什么问题。我也尝试了takeUntil,但它也会引发相同的错误。