简体   繁体   English

如何从 Angular8 中的另一个组件传递一个组件的值(独立组件)

[英]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.

相关问题 如何将对象从一个组件传递到另一个组件 - how can I pass an object from one component to another in angular 如何在Angular2中将值从一个组件传递到另一个组件? - How to pass value from one component to another component in Angular2? 如何将* ngIf值从一个组件传递到另一个组件? - How can I pass an *ngIf value from one component to another? Angular,当组件不是父/子时,如何将值从一个组件传递到另一个组件? - In Angular, how to pass value from one component to another when the components are not parent/child? 如何以角度从另一个组件传递对象? - How can i pass object one component from another component in angular? 如何以角2将变量值从一个组件传递到另一组件 - How to pass variable value from one component to another in angular 2 如何将值从一个组件传递到另一个组件? (有角度的) - How to pass value from one component to another? (Angular) 如何在Angular2中将变量值从一个组件传递到另一个组件 - How to pass variable value from one component to another in Angular2 如何将 object 从服务传递到 Angular8 中的组件? - How to pass an object from a service to a component in Angular8? 将文本字段的值从一个组件传递到 angular 8 中的另一个组件 - Pass a value of text fields from one component to another component in angular 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM