![](/img/trans.png)
[英]Angular 2: Have Child Route Component Replace Parent in router-outlet
[英]Pass child to parent component (child render in router-outlet) ? in Angular?
我一直在做一個項目,但我遇到了目前陷入困境的情況。 #situation:我有一個在應用程序路由中注冊的子組件。 所以這是從主組件 app.component.ts 中的路由器出口渲染的。 導航欄組件也在渲染。 所以問題是在子組件中發生了一些事情,我想通知導航欄組件。 為此,我無法使用 Output() 參數來實現這一點,因為該組件正在動態呈現在路由器插座內。 所以請讓我知道該怎么做。 幫助將不勝感激。
這是我的 app.component.html 代碼。
<app-nav *ngIf="_authService._isLoggedIn()"></app-nav>
<div class="container-fluid">
<app-login *ngIf="!_authService._isLoggedIn()"></app-login>
<div class="col-md-9">
<router-outlet *ngIf="_authService._isLoggedIn()"></router-outlet>
</div>
</div>
</div>
您可以在服務中使用主題,例如:
someThing = new BehaviorSubject<number>(0);
currentsomeThing = this.someThing.asObservable();
用這個改變孩子的 currentSomething:
this.examleService.someThing.next(digit);
並在導航欄中訂閱:
this.examleService.currentsomeThing.subscribe(res => ...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.