簡體   English   中英

如何從 Angular8 中的另一個組件傳遞一個組件的值(獨立組件)

[英]How can I pass value from one component from another component in Angular8 (Independent components)

我想重置另一個組件的變量值。 2個組件是獨立的。 我想重置特定變量的值。 值更新后需要刷新該組件的 UI 以反映更改。

在 AngularJS 中期待像Broadcast/Emit 和 On 之類的東西

可以用 RxJS 做點什么嗎? 如果是,請分享一些有用的鏈接。

您可以使用 Service 來共享 EventEmitter: https ://angular.io/api/core/EventEmitter

@Injectable()
export class YourSharedService {
  private _event = new EventEmitter<any>();

  get event(): EventEmitter<any> {
    return this._event;
  }
}

然后在第一個組件中發出:

this.yourService.event.emit();

並訂閱另一個:

    this.yourService.event.subscribe(() =>  {});

有用,僅當您的組件真正獨立時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM