【发布时间】:2019-03-04 12:41:33
【问题描述】:
将变量的类型更改为 Observable 后,我在代码的其他地方收到了我无法处理的错误消息。
authService 中的 Observable 我这样创建:
private activeBusinessCase = new BehaviorSubject<string>(null);
public activeBusinessCase$ = this.activeBusinessCase.asObservable();
在同一服务中,我收到错误消息..
“行为主体”类型上不存在属性“toLowerCase”
..对于这行代码:
this.router.navigate ([Constants.routing.explorer + this.activeBusinessCase.toLowerCase ()]);
在我的 home.component.ts 中,我收到以下错误消息..
属性“activeBusinessCase”是私有的,只能在“UserAuthService”类中访问。
..对于这行代码:
ngOnInit () {
this.router.navigate ([Constants.routing.explorer + this.authService.activeBusinessCase.toLowerCase ()]);
}
但最重要的错误消息在我的 httpService 中,其中没有任何作用:
getResource (key: string, lang: string): Observable <any> {
const headers = new HttpHeaders ({'Accept': 'text / html'});
return this.httpClient.get ('/ resources /' + key,
{
headers: headers,
responseType: 'text',
params: new HttpParams ()
.set ('businessCase', this.authService.activeBusinessCase? this.authService.activeBusinessCase:
environment.default_business_case)
.set ('long', long)
}) Pipe. (
catchError (() => {
return this.translateService.get ('Not-available'). pipe (
map (res => '<h4 style = "text-align: center">' + res + '</ h4>'));
})
);
}
getResources (long: string): Observable <Resource []> {
return this.httpClient.get <any> ('/ resources',
{
params: new HttpParams ()
.set ('long', long)
.set ('businessCase', this.authService.activeBusinessCase? this.authService.activeBusinessCase:
environment.default_business_case)
});
}
这里是控制台中的错误信息:
错误 TS2341:属性“activeBusinessCase”是私有的,只能在“UserAuthService”类中访问。
我仍然是 Angular 的初学者,感谢任何详细的帮助。
【问题讨论】:
标签: angular debugging rxjs observable behaviorsubject