Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
Rendering multiple components on tabs from array with Angular Material

I'm trying to render some components in a <mat-tab-group> from an array of components. This way:

TS

...
steps = [
    {label: "Step 1", content: [Step1Component]},
    {label: "Step 2", content: [Step2Component]},
    {label: "Step 3", content: [Step3_1Component, Step3_2Component]},
    {label: "Step 4", content: [Step4Component]},
]
...

HTML

...
<mat-tab-group>
    <div *ngFor="let step of steps;">
        <mat-tab label="{{step.label}}">
            <div *ngFor="let component of step.content;">
                <ng-container *ngComponentOutlet="component"></ng-container>
            </div>
        </mat-tab>
    </div>
</mat-tab-group>
...

All works fine, but one of my components now needs to have an MatDialog, so that component looks like this:

TS

...
@Component({
    selector: 'app-step2',
    templateUrl: './step2.component.html',
      : ['./step2.component.scss']
})
export class Step2Component implements OnInit {
    constructor(public dialog: MatDialog) { }
}
...

So I've noticed that when component's constructor has an argument (on this example, public dialog: MatDialog), my application stops working with this error:

Error: src/app/pages/home/home.component.html:40:85 - error TS2322: Type '(typeof Step1Component)[] | (typeof Step2Component)[]' is not assignable to type '((typeof Step1Component)[] & NgIterable<typeof Step1Component>) | null | undefined'.

Can someone help me fixing this? I can't find any viable solution to this.

Thanks!

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda