I have old code that looks something like this:
<as-split unit="pixel" #mainViewSplit class="custom-gutter" direction="horizontal"
gutterSize="2">
<as-split-area #propertiesContentPanel [size]="(propertiesWidth | async)"
[minSize]="350" maxSize="{{propertiesMinimized? minPanelWidth : '*'}}"
*ngIf="(propertiesSplitVisible | async)" [order]="splitOrder.properties">
<app-properties-content-panel></app-properties-content-panel>
</as-split-area>
<as-split-area #someContentPanel [size]="(someWidth | async)" [minSize]="350"
maxSize="{{someMinimized? minPanelWidth : '*'}}" *ngIf="(someSplitVisible | async)"
[order]="splitOrder.some">
<app-some-content-panel></app-some-content-some>
</as-split-area>
</as-split>
In the above html there's as-split-component that contains 2 as-split-area directives (https://angular-split.github.io/documentation). Also in the html above there's 2 template reference variables used to reference the 2 as-split-area directives. They are
#propertiesContentPanel
and
#someContentPanel
In the class (.ts) files they are referenced like this:
@ViewChild('propertiesContentPanel') propertiesContentPanelSplit: SplitAreaDirective;
@ViewChild('someContentPanel') someContentPanel: SplitAreaDirective;
In reality there's a lot more of these as-split-areas but for simplicity only 2 are shown. I want to add all the as-split-area directives to the as-split component with ngFor. So the code would look like this:
<as-split unit="pixel" #mainViewSplit class="custom-gutter" direction="horizontal" gutterSize="2">
<ng-container *ngFor="let splitItem of splitData">
<as-split-area id="splitItem.id" *ngIf="(splitItem.isVisible | async)
[size]="(splitItem.width | async)" [minSize]="splitItem.minSize"
maxSize="{{splitItem.isMinimized? minPanelWidth : '*'}}" [order]="splitItem.order">
<ng-container *ngTemplateOutlet="splitItem.template"></ng-container>
</as-split-area>
</ng-container>
</as-split>
Above all the templates and related .ts code used in
<ng-container *ngTemplateOutlet="splitItem.template"></ng-container>
are omitted for simplicity.
Everything else works but I cannot now reference the as-split-area directives in the code anymore because template reference variables are missing. How can I bind to as-split-area directives in the refactored ngFor-version so that I can still reference them in the class file with the 2 ViewChild I have (propertiesContentPanel and someContentPanel)?
I would like to do something like this:
<as-split-area #="splitItem.referenceVariable"
But this doesn't work. I have also omitted type of splitItem also from the question to avoid confusion.
#
creates a variable which you can then access viaViewChild()
. You could use a directive (or input) to pass the template to the component instead.