DEV Community

Kathiresan Moorthy
Kathiresan Moorthy

Posted on

Create Variable to re-use within html template

Hi,

If I need to create a variable in my html template that I can re-use in multiple places within a section for example, how can I do it in Angular?

for example:


my-component.html

<div let-myVar="computedOnComponent()">
   <p>{{myVar}}</p>
   <div [attr]="myVar">Test</div>
</div>

my-component.ts

computedOnComponent(): = () => "some value";

Enter fullscreen mode Exit fullscreen mode

Top comments (0)