1

Is there anything wrong with passing a value into a custom component like this? I noticed that when I console.log inside someFunction it is called many times when the component is loaded. Can someone explain?

HTML

<custom-component [someInput]=“someFunction(‘someParameter’)></custom-component>

TS

someFunction(someParameter) {
    return someValue
}
0

1 Answer 1

3

YES, You are right,

In angular you should not call functions in template.

Reason

The main goal of angular is, Rendering the DOM when detecting any changes. So If angular detect any changes/updates in your application, It will re-render the template. So when It re-render each time, The function you used in template(props) will be called.

Always follow the best practices

why-you-should-never-use-function-calls-in-angular-template-expressions

Sign up to request clarification or add additional context in comments.

2 Comments

Good luck dude!
That thing is a common mistake when starting with Angular. +1 for the easy to digest and straight to the point answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.