#Function loads twice

17 messages · Page 1 of 1 (latest)

fast dawn
#

Hello i have in one of mine components a call function:

#

its only ones in there but if i check the console

#

its executed twice

#

can anybody tell why its like that?

somber flare
#

Function calls aren't recommended in templates as there are called on each change detection.

fast dawn
#

how could i change that...

fast dawn
somber flare
#

On refresh/loads the component will be initialized. You can initialize a local property of your component with related data

fast dawn
#

how i can do that?

#

do you have like an code example

somber flare
#

What do you want to display in the template?

fast dawn
#

i know i will be adding it soon, the code of the function i want firstly that the function only get load onnce

somber flare
#
export class Component {
  myData = myFunction() ;
}
#
<div>{{myData}}<div/>