Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Activate sub-pages from a main page

$
0
0

In your TypeScript/JavaScript have a property under your Page class that will hold the dynamic value. For instance we will call it buttonColor.

this.buttonColor = 1;

Change that value to whatever you want it at any time you would like to change the color of that button.

Then in your html do the follwing:
<button [ngClass]="{primary: buttonColor ==1, secondary: buttonColor==2, danger: buttonColor=3}">Test button</button>

  • Instead of primary, secondary, and danger you can use any other button class or use your own classes.
  • Instead of setting the value of our property ( this.buttonColor ) to a number, you can set it to anything else that suits your needs. I recommend a boolean if you only have two options. Or a string if you need to remember what each option refers to (numbers can get confusing).

--

Alternatively you may use ngStyle which will allow you to add dynamic styling to an object. Example:

this.buttonColor = '#f0f0f0';

<button [ngStyle]="{'background-color': buttonColor}">Test</button>


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>