I have a button on tag with text "Unfreeze". I want to toggle it to "Freeze" on click on the button. Here is ny code:
<a class="btn btn-primary full-width" (click)="clickFreeze($event)">
<i class="fa fa-plus-circle"></i>Unfreeze</a>
private clickFreeze(event) {
console.log("event.srcElement.childNodes[1].textContent", event.srcElement.childNodes[1].textContent);
if(event.srcElement.childNodes[1].textContent =='Unfreeze'){
event.srcElement.innerText="Freeze and Save";
} else if(event.srcElement.innerText =='Freeze and Save'){
event.srcElement.innerText="Unfreeze";
}
}
For some reason it does not work. event.srcElement.childNodes[1].textContent
is equal to "Unfreeze" when I console it but it does not enter the if loop.
I am not sure why you are using this approach, you can simply toggle text conditionally like this -
.html
<a class="btn btn-primary" (click)="isFreeze = !isFreeze">
<i class="fa fa-plus-circle"></i>
{{isFreeze ? "Unfreeze" : "Freeze and Save"}}
</a>
.ts
isFreeze: boolean = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With