All,
I would like to use *ngIf
to remove a section of a page if a specific router-outlet
has a component.
I've tried searching through ActivatedRoute
and Router
, but I can't seem to figure it out. How do you check if a specific router-outlet
is in use?
Can be solved like this:
<div [hidden]="!myOutlet.isActivated">
<router-outlet name="my-outlet" #myOutlet="outlet"></router-outlet>
</div>
No changes in component class needed.
I figured this out. You need to use the events for router outlets. However, you can't use ngIf
because events won't be fired unless the outlet is in the dom.
ts
showOutlet: boolean;
onActivate(event : any) {
this.showOutlet = true;
}
onDeactivate(event : any) {
this.showOutlet = false;
}
html
<div [hidden]="!showOutlet">
<router-outlet name="my-outlet"
(activate)="onActivate($event)"
(deactivate)="onDeactivate($event)"></router-outlet>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With