1

I am using *ngFor with ng-tabset. But doing so would not paint the tabs at all. do ng-tabs need any dependency to be called in the module.ts file

          <ngb-tabset>
            <ng-tab *ngFor="let item of [1,2,3]" title="{{item}}">
                <ng-template ngbTabContent> {{item}}</ng-template>
            </ng-tab>



        </ngb-tabset>

It does work when I name it statically though as shown in the example

 <ngb-tabset>
        <ngb-tab title="Simple">
          <ng-template ngbTabContent>
            <p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth
            master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh
            dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum
            iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
          </ng-template>
        </ngb-tab>
        <ng-tab *ngFor="let item of items" title=" {{item}}">
            <ng-template ngbTabContent> {{item}}</ng-template>
  </ng-tab>

1 Answer 1

2

As far I understand you are pointing to single template for every Tab

<ng-template ngbTabContent> {{item}}</ng-template>

You can try with ngTemplateOutlet to render multiple templates inside each and every Tab

<ngb-tabset>
    <ng-tab *ngFor="let tab of tabs" title="{{tab.title}}">
         <ng-container [ngTemplateOutlet]='tab.content'></ng-container>
    </ng-tab>
</ngb-tabset>
Sign up to request clarification or add additional context in comments.

3 Comments

I am getting this error If I tried it TypeError: templateRef.createEmbeddedView is not a function
You have to pass template reference in your typescript using ` @ViewChild('tabTemplateRef') tabTemplateRef: TemplateRef<any>;` tabs= [{ title: 'About Us', content: this.tabTemplateRef },
what if I do not want to add a view child and just want to populate it from a collection?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.