The question may look kind of confusing but let's say I have a button like following:
<button type="button" class="menu-button" [disabled]="isInvalidForm()">Save</button
isInvalidForm() {
console.log('I am running!');
return this.nameValidator.errors || this.lastnameValidator.errors;
}
And when it is like this (I just simplified the form for the sake of the question) , it logs 100s of 'I am running!' as it is called that much. Even though when I click around the form, it is called another 100 times..
I doubt that this way of checking the button is enabled or not does not look good at all.. One other way is triggering the function on the button click but that is definitely not what I want. What would be the best to avoid tons of calls to that function to disable a simple button? (or is it really OK to use function in DOM elements? )
or in short, is it the exact same thing using:
<button type="button" class="menu-button" [disabled]="isInvalidForm()">Save</button>
with:
<button type="button" class="menu-button" [disabled]="nameValidator.errors || lastnameValidator.errors">Save</button>