Request to publicly expose ResultTemplateContext
Author: DanAtkinsonCreated Aug 14, 2026Updated Aug 14, 2026
Please can ResultTemplateContext be exposed in publicly, presumably in src/typeahead/public-api.ts?
It would help with strongly-typing ng-template elements where the default is to treat all variables as any.
I currently have the following directive to help:
import { Directive, Input } from "@angular/core";
@Directive({ selector: 'ng-template[typedContext]', standalone: true })
export class TypedTemplateDirective<T extends object> {
@Input() typedContext!: T;
static ngTemplateContextGuard<T extends object>(directive: TypedTemplateDirective<T>, context: unknown): context is T {
return true;
}
}In my component, this would be referenced thus:
@Component({... imports: [TypedTemplateDirective])
export class MyComponent {
@ViewChild('typeaheadListTemplate') typeaheadListTemplate: TemplateRef<ResultTemplateContext>;
readonly resultTemplateContext!: ResultTemplateContext
}And in the HTML, I would have this:
<ng-template [typedContext]="resultTemplateContext" #typeaheadListTemplate let-result="result" let-query="term">
<p title="{{ result.Name }} ({{ result.Code }})">
<span class="text-underline">{{ result.Name }}</span>
<span class="text-dark">{{ result.Code }}</span>
</p>
</ng-template>However, because ResultTemplateContext is not exposed publicly, I cannot do this approach, so this ng-template cannot be strongly-typed.
Kind regards Dan
Source: ng-bootstrap/ng-bootstrap