我怎样才能只用一个行为主体来做到这一点?
我有这样的代码:
private _fileData$: BehaviorSubject<string> = new BehaviorSubject<string>('');
private _storageData$: BehaviorSubject<Array<string>> = new BehaviorSubject<Array<string>>([]);
private constructor() {
this._fileData$.subscribe({ next: (fileData: string) => this._storageData$.next(fileData.toString().split('\r\n')) });
所以我在 _fileData$ 中有一些字符串数据,我想按行分割它,这样我就得到字符串数组,所以我创建 _storageData$ 将它们放在这里。 它像我想要的那样工作,但是我怎样才能只使用一个BehaviorSubject来做到这一点呢?
I have this code:
private _fileData$: BehaviorSubject<string> = new BehaviorSubject<string>('');
private _storageData$: BehaviorSubject<Array<string>> = new BehaviorSubject<Array<string>>([]);
private constructor() {
this._fileData$.subscribe({ next: (fileData: string) => this._storageData$.next(fileData.toString().split('\r\n')) });
So i have some string data in _fileData$ and I want to split it by lines so I get Array of strings, so im creating _storageData$ to put them here.
It works like I want to, but how can I do it using only one BehaviorSubject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后你可以在你的视图中绑定它:
map
是一个 rxjs 运算符Then you can bind to it in your view:
map
is an rxjs operator