i am building autocomplete in NativeScript and Angular (this question is valid for pure Angular also).
Markup looks like this:
<StackLayout>
<TextField #keywords [hint]="options?.hint" [(ngModel)]="occupation"
(textChange)="keywordsInputChange$.next(keywords.text)">
</TextField>
<ng-container *ngTemplateOutlet="parentTemplate"></ng-container>
<ScrollView orientation="vertical" height="200" *ngIf="dataItems?.length > 0" class="m-r-16 m-l-16 search-view">
<ListView [items]="dataItems" (itemTap)="onItemTap($event)">
<ng-template let-item="item">
...
</ng-template>
</ListView>
</ScrollView>
and it will be used from outside:
<px-lookup (selected)="onOccupationSelected($event)" [options]="occupationLookupOptions">
<ng-template let-item>
<StackLayout class="search-item" backgroundColor="red">
<Label [text]="item.text"></Label>
</StackLayout>
</ng-template>
</px-lookup>
As you see i would like to pass custom template to my lookup which will be used by ListView. I am am retrieving that template like this
@ContentChild(TemplateRef, { static: false }) parentTemplate: TemplateRef<any>;
I can render it in lookup without any problem by defining
<ng-container *ngTemplateOutlet="parentTemplate; context: { $implicit: item }"></ng-container>
However when i am trying to put it to LietView which also requires template i cannot make it to work. I am geting errors like 'Error: No suitable views found in list template! Nesting level: 0' either items are rendered just as [Object object]
I have tried these options:
<ListView [items]="dataItems" (itemTap)="onItemTap($event)">
1. Option ===> <ng-container *ngTemplateOutlet="parentTemplate"></ng-container> -->
2. Option ===><ng-content></ng-content>
3. Option ===> <ng-template let-item="item"> (top template that is required by ListView)
<ng-container *ngTemplateOutlet="parentTemplate; context: { $implicit: item }"></ng-container> (Tried to render another template with current one by passing item down the pipe)
</ng-template>
</ListView>
Does somebody knows the way how I can attchieve that?
Thanks