I have simple code where I display the value of an input in HTML template from an array of data that I have in Typescript. I ran into a problem, where the data wasn't loaded fast enough and I was getting errors until the data was loaded. I fixed that by checking if the endTime or StartTime are empty. while trying to fix the problem I've noticed that my console.log is printing many times. I expected that this function would run once. Why is it running many times? Am I doing something wrong? Or is this how angular is supposed to work?
To give more information this is HTML code.
I have multiple cards that have 2 input value that call my function returnTime()
<mat-card *ngFor="let item of requestVehicles.controls; let pointIndex=index" [formGroupName]="pointIndex">
The function is called like this
<input [value]="returnTime(pointIndex, true)">
The actual function
returnTime(pointIndex, isEnd) {
if (this.data.isEdit) {
console.log('ENDTIME =======' + this.endTime + ' STARTTIME =========' + this.startTime);
// rest of the logic that should not be relevant.
} else {
return '';
}
}
the maximum value of pointIndex is usually 2-3. so that should not explain the amount of console logs.

valueattributes are worthless in Angular. And to answer you, functions, getters and variables in the template are checked several times by Angular to detect changes. Just by moving your mouse around, you will see that it triggers them several times. It's usually a bad practice to bind functions to inputs, they should be bound only to outputs (events).ngModelorformControlattribute : if you want to give it a value, give a value to that model/form control.ControlValueAccessorthat will handle both date & time.