I'm using Angular 16.
I have to create a component to render the multi-stepper components and the component usage will be like
<!- app.component.html -->
<app-multi-step>
<app-multi-step-panel title="Basic">
<ng-template panelContent>
<div>Panel content</div>
</ng-template>
<ng-template panelFooter>
<button (click)="handleNext()">Next</button>
</ng-template>
</app-multi-step-panel>
<app-multi-step-panel title="Settings">
<ng-template panelContent>
<div>Settings content</div>
</ng-template>
<ng-template panelFooter>
<button (click)="handleNext()">Next</button>
</ng-template>
</app-multi-step-panel>
</app-multi-step>
Where the app-multi-step can have n-number of app-multi-step-panel which can have two directives panelContent to render contents and panelFooter to render footer content.
To achieve this, I created a component multi-step
# multi-step.component.ts
@Component({
selector: 'app-multi-step',
templateUrl: './multi-step.component.html',
styleUrls: ['./multi-step.component.scss']
})
export class MultiStepComponent implements AfterContentInit {
@ContentChildren(MultiStepPanelComponent) panels: QueryList<MultiStepPanelComponent>;
panelList: Array<string> = [];
projectedIndex = 0;
ngAfterContentInit() {
this.panelList = this.panels.map(p => p.title);
}
setProjection(index) {
this.projectedIndex = index;
}
}
and the HTML content
<!-- multi-step.component.html -->
<div class="card">
<div class="card-body">
<div class="multisteps-form__progress">
<button [disabled]="i > projectedIndex" (click)="setProjection(i)" class="multisteps-form__progress-btn" [class.js-active]="i <= projectedIndex" type="button" title="{{panelTitle}}" *ngFor="let panelTitle of panelList; let i=index">
{{panelTitle}}
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-8 m-auto">
<ng-content select="app-multi-step-panel"></ng-content>
</div>
</div>
This is working as expected, except I want to render one app-multi-select-panel at once and change the component based on the projectIndex value change.
How can I achieve it using the above setup? Any other approach suggestion is welcome as well.
Have a flag called "selected" in "app-multi-step-panel" component, the component will be displayed only if the selected is true. In the "app-multi-step" component, make the selected flag of "app-multi-step-panel" in first index to be true. Likewise, have a UI in "app-multi-step" to change the index