I would like to ask about *ngIf binding to function return value. Will it have performance overhead when comparing *ngIf binding to property.
This is only sample code for asking concept, the data structure is complex than that in DataService. The enable flag will be saved in a map object. This is just a simple expression:
In typescript service
export class DataService() {
private enable: boolean;
isEnable() {
return enable;
}
getEnableValue() {
return enable;
}
update(flag: boolean) {
enable = flag;
}
}
In html,
<div *ngIf="isEnable()">
<p> {{ testObject.value }}</p>
</div>
In typescript,
isEnable() {
return this.dataService.isEnable();
}
vs
In html,
<div *ngIf="isEnable">
<p> {{ testObject.value }}</p>
</div>
In typescript,
isEnable: boolean;
ngOnInit() {
isEnable = this.dataService.getEnableValue()
}
For *ngIf="isEnable", I am able to understand。 But for function binding,is angular check the property in the function and monitor it changes? Any performance difference?
Thanks a lot.