节点BehaviorSubject问题仅获取空对象
我正在使用 Angular 版本 7 并尝试使用 BehaviorSubject
但是当我获得该值时,我总是收到一个空对象
line: 315 | let value: any = await this._service.machine$.pipe(take(1)).toPromise()
Emmit
this._service.emitterMachineSelected('new')
I am using Angular version 7 and trying to use a BehaviorSubject
but when I get the value, all times I receive an empty object
line: 315 | let value: any = await this._service.machine$.pipe(take(1)).toPromise()
Emmit
this._service.emitterMachineSelected('new')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_machine 的默认值
_machine 是一个包含空对象的
BehaviorSubject
(首先)。 ({}
是一个空对象)。这就是您阅读以下行的方式:因此,当您获取该值时,您将得到一个空对象(
BehaviorSubject
的默认值)。使用
.next
发出一个值一段时间后,它包含字符串
"new"
您没有在任何地方获取此值,因此您不应期望看到它任何地方。
_machine's default value
_machine is a
BehaviorSubject
that (to start with) contains an empty object. ({}
is an empty object). That's how you read the following line:So when you grab that value, an empty object (The default value of the
BehaviorSubject
) is what you get.Using
.next
to emit a valueSome time later, it contains the string
"new"
You're not grabbing this value anywhere, so you shouldn't expect to see it anywhere.