خرید بک لینک

Vote count: 1

I have object markers with all different Id's, now I want to set extra styling when the id > 100

Here the code is:

<span *ngIf="result.object.reference > 100" class="tooltip-data">
   {{ result.resource.display_name }}
</span>

But how do I add extra styling like style="left: 12px"

asked 6 mins ago

1 Answer

Vote count: 1

You can bind to a style conditionally like

<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 don't want to set a style at all if id <= 100 this might work

<span *ngIf="result.object.reference > 100" class="tooltip-data" 
    [ngStyle]="getStyle(id)">

noStyle = {};
gT100Style = {left: '12px'};
getStyle(id) {
  retu id > 100 ? this.gT100Style : this.noStyle;
}

It is important, that noStyle and gT100Style are defined outside getStyle() otherwise change detection would cause troubles because every call would retu a new style object instance.

answered 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 27 خرداد 1395 ساعت: 20:03

صفحه بندی