0

I have a child control that I want to activate inside a mat-tab-group control (I don't want to use mat-nav because I want the animations provided by mat-tab-group - and it's just easier to let the tab control handle component creation.

However my child route is activating in multiple places.

<mat-tab-group>

    <mat-tab label="Animals">

        <ng-component *ngIf="showCats">
            Cats
        </ng-component>

        <ng-component *ngIf="!showCats">
            Dogs
        </ng-component>

    </mat-tab>

    <mat-tab label="FAQ">
        <router-outlet></router-outlet>
    </mat-tab>

</mat-tab-group>
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • May also be useful https://stackoverflow.com/questions/40413133/angular-2-throwing-error-outlet-is-not-activated/54849133#54849133 – Simon_Weaver Feb 24 '19 at 05:49

1 Answers1

1

This can occur if you put ng-component instead of ng-container

Very easy mistake to make - but the router will consider ng-component as some special type of child and automatically create a router-outlet inside it.

The solution is simple - use ng-container

 <ng-container *ngIf="showCats">CATS</ng-container>
Community
  • 1
  • 1
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689