Search code examples
angularangular14

What is the type of a ng-template for strict typing in angular?


i have a angular application running on version 14, and lets consider a component inside it where i have html as below

<button (click)="myfn(template)">click mE </button>
<ng-template #template>
  <some html here>
</ng-template>

and in component.ts file

public funtion myfn(template:any): void {
   //some action with this template like modal opening or something
}

Now how would i cast a type for template here in component file

I am expecting the correct type for my function parameter template ?


Solution

  • The type is TemplateRef so:

    public funtion myfn(template:TemplateRef<HTMLElement>): void {
       //some action with this template like modal opening or something
    }
    

    https://angular.io/api/core/TemplateRef