To apply styles conditionally, you can use the following methods:
<span *ngIf="result.object.reference > 100" class="tooltip-data"
[style.left.px]="id > 100 ? 12 : 0">
or
<span *ngIf="result.object.reference > 100" class="tooltip-data"
[style.left]="id > 100 ? '12px' : '0px'">
If you only want to set a style when id > 100
, you can use this approach:
<span *ngIf="result.object.reference > 100" class="tooltip-data"
[ngStyle]="getStyle(id)">
noStyle = {};
gT100Style = {left: '12px'};
getStyle(id) {
return id > 100 ? this.gT100Style : this.noStyle;
}
Ensure that noStyle
and gT100Style
are defined outside of getStyle()
to avoid issues with change detection.
Another option is:
<span *ngIf="result.object.reference > 100" class="tooltip-data"
[ngStyle]="id > 100 ? {left: '12px'} : {}">
Check out this Plunker example for reference.