[英]How can I pass value from one component from another component in Angular8 (Independent components)
I want to reset the value of a variable of another component.我想重置另一个组件的变量值。 2 components are independent ones. 2个组件是独立的。 I want to reset the value of the particular variable.我想重置特定变量的值。 Once the value is updated need to refresh the UI of that component to reflect the changes.值更新后需要刷新该组件的 UI 以反映更改。
Expecting something like Broadcast/Emit and On in AngularJS在 AngularJS 中期待像Broadcast/Emit 和 On 之类的东西
Is it possible to do something with RxJS?可以用 RxJS 做点什么吗? If yes please share me some useful links.如果是,请分享一些有用的链接。
you can use a Service to share an EventEmitter: https://angular.io/api/core/EventEmitter您可以使用 Service 来共享 EventEmitter: https ://angular.io/api/core/EventEmitter
@Injectable()
export class YourSharedService {
private _event = new EventEmitter<any>();
get event(): EventEmitter<any> {
return this._event;
}
}
Then just emit in the first component:然后在第一个组件中发出:
this.yourService.event.emit();
And subscribe in the other:并订阅另一个:
this.yourService.event.subscribe(() => {});
Usefull, only if your components are really independent.有用,仅当您的组件真正独立时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.