Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically changing a button icon

Given the following button,

  <button
      icon = 'ui-icon-check'
      type = 'text'
      pButton
      label = 'Age'
      iconPos = 'right'></button>

I would like to dynamically change the icon assigned to the button icon property:

My attempt is as shown below:

ng.html

  <button
      [icon] = 'btnIcon'
      type = 'text'
      pButton
      label = 'Age'
      iconPos = 'right'></button>

ng.component

....
btnIcon: string = 'ui-icon-check'

The icon is correctly assigned when the component initializes.

However, when I do

ng.cmponent

if(this.form.valid)
{this.btnIcon = 'ui-icon-information'}

although the form is valid, the icon does not change as expected.

Any idea is welcome. Thanks

like image 569
st_clair_clarke Avatar asked Jan 26 '26 10:01

st_clair_clarke


1 Answers

As per the comment noted give this a try

 <button
      [attr.icon] = 'btnIcon'
      type = 'text'
      pButton
      label = 'Age'
      iconPos = 'right'></button>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!