Is it possible to call a component method from HTML, or should I create another component to handle formatting?
<div *ngFor="let item of items">
<div class="title">{{ item.Title }}</div>
<p>
callComponentMethodHere({{item}})
</p>
</div>
Is it possible to call a component method from HTML, or should I create another component to handle formatting?
<div *ngFor="let item of items">
<div class="title">{{ item.Title }}</div>
<p>
callComponentMethodHere({{item}})
</p>
</div>
but you should avoid that because the method will be called every time change detection runs. It's better to call the method in code (for example in the
constructor()
,ngOnInit()
, or an event handler, assign the result to a property and from the view bind to that property instead.Calling event handlers is fine of course: