0

i would like to know if it is possible to use variable, declared in my ts file for styling my ionic components.

I know i can do it by declaring the variables as globals, but as they are not fixed, i have to declare then in my ts file.

Example: i have this code, witch is working:

  <ion-col style=" height: 170px; background: rgb(226, 45, 144)" > {{room.name}}</ion-col>

But i want something like:

<ion-col style=" height: room.height; background: room.bckg_color" > {{room.name}}</ion-col>

Thanks for your help.

1

1 Answer 1

1

I don't have an account for Ionic Academy, can you share the answer ?

Otherwise, this would be my answer, this is called "inline style", and it can be defined with something like:

<ion-col [style.height.%]="room.height" [style.backgroundColor]="room.bckg_color" > 
   {{room.name}}
</ion-col>

Or Ionic 1

<ion-col [ngStyle]="{height: room.height, backgroundColor: room.bckg_color}">
   {{room.name}}
</ion-col>
Sign up to request clarification or add additional context in comments.

Comments

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.