how to create an angular templateref in code

Viewed 2255

I need to create an instance of TemplateRef in the .ts file and pass this as a parameter to a component. Is it possible to do this. What I want to do is to just create an instance of a TemplateRef with some content inside. I tried searching the web but couldn't find any concrete example on this.

1 Answers

You can query for the TemplateRef from a Component or a Directive via Query

See Template Ref


@ViewChild('templateref') public templateref: TemplateRef<any>;

constructor() { }
...

You can now access the injected value with this.templateRef Working Example in Stackblitz

Related