Suppose I have this in my template:
<img src="..." alt="myService.getImgAlt()" />
This works... But at every change detection this function will be called, which is bad for performance. Is it possible to remove this attribute (or entire element) from change detection after the first time getImgAlt()
is called?
I want to call myService
from the template directly, which means a function call is needed and I can't just use a variable from the component. The component just defines the service so the template has access to it:
export class MyComponent {
constructor(public myService: MyService) {}