简体   繁体   English

使用来自可观察数据的角度4单击事件

[英]Angular 4 click event using data from observable

I have a smart component, with some data being selected from the store with 我有一个智能组件,可以从商店中选择一些数据

this.user$ = store.select(fromRoot.getUser) 

A child component emits up to the smart component off the back of a button click. 子组件会在单击按钮后释放出智能组件。 Inside this event handler (in the smart component), I want to use the value the value of 在此事件处理程序内(在智能组件中),我想使用以下值:

this.user$

My only thought is to pass down 我唯一的想法就是传下来

user$ | async

into the dumb and to then emit the user back up with the click event. 进入哑巴,然后将用户与click事件一起备份。 Is this the best approach? 这是最好的方法吗?

You can do this too, if you don't wan't to pass the observable with the async pipe: 如果您不想通过异步管道传递可观察对象,也可以这样做:

public user: any;
this.user$.subscribe(user => this.user = user);

Then you can pass this.user, and not the observable. 然后,您可以传递this.user,而不是可观察的。

But your approach is perfect. 但是您的方法是完美的。 This is just an alternative. 这只是一种选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM