尽管我已经安装了所有相关的软件包并遵循了 react-navigation 指南(https://reactnavigation.org/docs/getting-started#installation),但我还是收到了 RNSScreen 错误,但没有任何效果对我有用。
我想将值(任何数据)从服务返回到组件作为可观察对象。经过几次深入研究 observables 发现以下解决方案:
class AppService {
getData(value) {
// do we have any other best way to return value as an observable
return Observer.create((observer) => {
observer.next(value);
});
}
}
class AppComponent implements OnInit {
ngOnInit() {
this.dataService$ = this.appService.getData().subscribe((data) => {
// do some task with data
});
}
}
Run Code Online (Sandbox Code Playgroud)