2

I want to change the div width based on the following condition,

<div [ngStyle]="'width': selectedTab =='Home' ? '50%' : '100%'">

</div>

I am getting the tab which has been selected in "selectedTab".

I have two tabs.

1) Index

2) Home

If I select Index tab, The div width should be "100%". Incase If I select home tab, the div width should be "50%". I have written [ngStyle] condition but it is not working.

Please help me how can I handle this situation.

1
  • Might try a two way binding that you change based on which tab you are currently on. Commented Aug 28, 2018 at 13:49

2 Answers 2

3

Try this :

<div [style.width]="selectedTab =='Home' ? '50%' : '100%'"></div>
Sign up to request clarification or add additional context in comments.

Comments

1

You can use ngStyle for this.

Stackblitz Demo

<div [ngStyle]="{
    'width.%': selectedTab =='Home' ? '50' : '100',
    'background-color': 'red'
  }">>
  div
</div>

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.