I have an Angular page using [ngStyle] = "getStyle()"
, when i run the page, seems the getStyle() has been called many times.
Could anyone explain why this behavior is happening?
Template:
<div class="toast" data-autohide="false" [ngStyle]="getStyle()">
<div class="toast-header">
<strong class="mr-auto text-primary">{{comment.username}}</strong>
<small class="text-muted">5 mins ago</small>
</div>
<div class="toast-body">
{{comment.comment}}
</div>
</div>
TS code:
getStyle(): Object {
this.x = Math.floor((Math.random() * 100));
this.y = Math.floor((Math.random() * 30));
console.log('random process ', this.x, this.y);
return {
left: this.x+'px',
top: this.y+'px'
};