0

Within our application we have to show/hide a button depending on some logic. What is a better place to define this logic (and why) ? In Html:

*ngIf='here goes the logic' 
//Or 
*ngIf='someBoolean' and in typeScript someBoolean = 'here goes the logic'.
2
  • 1
    It depends on what "better" means to you. It also depends on the complexity of the logic, what it depends on, when the value changes, etc. Make things correct. Then make things readable. Then make things testable. Then make things faster if you have a performance problem and if you can prove that it comes from there. Commented Jul 19, 2019 at 12:45
  • Yes, you are correct that the term better is vague. 1. Complexity of logic: (it's a onliner not very complex) 2. When the value changes: (After the ngInit it will not change anymore) Code is working and also readable. I'm not sure about the testability. Anyways, thanks for the quick reply for now i guess i leave the code in html Commented Jul 19, 2019 at 12:58

1 Answer 1

2

Putting the logic for ngIf in HTML is not a good idea. That logic will be evaluated every time there is a slight change. If the logic is complex, it might be a performance concern. I would suggest using a variable whenever it is possible.

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

Comments

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.