0

In my app I have variable of String. Which is have in string name of attribute to add.

ngOnInit()
{
   this.colAttibute = 'width-50';
}    

or it can be equal to 'width-100'. My app is get device width and set the value of this variable on onNgInit method. I want to set this attribute to my html code something like that:

<ion-list no-lines *ngIf="list">
  <ion-list-header>
    Лидеры продаж
  </ion-list-header>
  <ion-item class="categoryProductItem" *ngFor="let row of list;">
      <ion-row wrap >
        <ion-col *ngFor="let product of row" $colAttibute > <!--Here must be width-50 or width-100 attribute-->
          <a ion-item detail-push (click)="onSelectItem(product)" >
            <div class="categoryProductItemImage" *ngIf="product.getMainImage()">
                <ion-img [src]="product.getMainImage()['small_url']"></ion-img>
            </div>
            <h2>
              {{product.title}}
            </h2>
          </a>
        </ion-col>
      </ion-row>
  </ion-item>
</ion-list>

How to do this?

1 Answer 1

2

You can set the width like this:

<ion-col [attr.width-70]="flag">

Where flag is a boolean value indicating whether to apply this attribute or not. Unfortunately, you will need to list all the available attributes in order to support all of them dynamically.

Sign up to request clarification or add additional context in comments.

2 Comments

Note: To get the attribute removed the flag needs to be set to null. false doesn't remove it.
Do I may can somehow use "this" in template?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.