1

I want to change the button text once it is selected, logically it is working fine, initially YES button is highlighting once i click on it sightly change then if i hover disable symbol will show first image : before click second image : after click So what i want is , when i click on yes it should change it to NO and if i hover disable symbol has to show here is my HTML code

 <div>
                    <button type="button" class="confirm"
                            [disabled]="(isConfirmed && agree) || (isConfirmed && nutral)"
                            style="color: blue;"
                            (click)="sayYes()">
                        YES
                    </button>

</div>

enter image description here

enter image description here

3 Answers 3

1

the shortest way would be to conditionally render text inside of a button with innerText

<button [innerText]="condition ? 'YES' : 'NO'"></button>
Sign up to request clarification or add additional context in comments.

Comments

1

in yourComponent.html

<div>
                    <button type="button" class="confirm"
                            [disabled]="(isConfirmed && agree) || (isConfirmed && nutral)"
                            style="color: blue;"
                            (click)="sayYes()">
                       {{buttonTitle}}
                    </button>

</div>

In .ts

Create a new boolean variabile isClickedOnYes and inizialize it to false.

isClickedOnYes: boolean = false;
titleButton: string = 'YES'

When you click on button it became true and title became NO, when you click another time, it became false and title became YES;

In sayYes() function you can implement a logic like this:

sayYes() {
  if(this.isClickedOnYes == false){
    this.titleButton= 'NO'
    this.isClickedOnYes = true;
  }
  else {
    this.titleButton= 'YES'
    this.isClickedOnYes = false;
 }

 }

Comments

0

There are many ways to change the text. I would make an interpolation with your 'disabled' property conditions, like this:

<button type="button" class="confirm"
    [disabled]="(isConfirmed && agree) || (isConfirmed && nutral)"
    style="color: blue;"
    (click)="sayYes()">
        {{ (isConfirmed && agree) || (isConfirmed && nutral) ? 'NO' : 'YES' }}
</button>

And to disable button on hover, you can add css property 'pointer-events' with value 'none'. This will make your button unclickable, and then you style it on your own.

button:hover{
    pointer-events: none;
}

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.