我有一个包含字符串数据的observable,我需要检索此字符串并在JSON中使用它,但是我不确定如何在json对象中订阅observable。我对可观测对象还很陌生,因此可能缺少一些简单的东西。请参见下面的代码来更好地解释这一点(json中的href是一个字符串):
public settingsSideNav: Observable<ISideNavItem[]>;
public ngOnInit(): void {
this.settingsSideNav = this.testURL(this.betaUser());
}
public testURL(urmURL : any): Observable<ISideNavItem[]> {
return urmURL
.pipe(
first(),
map(
url => {
return [{ name: 'Manage Users', href: url}];
},
)
);
}
public betaUser(): Observable<string> {
return this.capabilityService.getCapabilities()
.pipe(
map(
capabilities => {
let manageUsersURL : string;
if (user = "test") {
url = "test";
} else {
url = "user";
}
return manageUsersURL;
}
)
);
}
}
<span [sideNavConfig]="settingsSideNav | async"></span>