Yog*_*ali 8 html javascript angular
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";
}
}
Run Code Online (Sandbox Code Playgroud)
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.
Par*_*ain 14
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>
Run Code Online (Sandbox Code Playgroud)
.ts
isFreeze: boolean = true;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
201 次 |
| 最近记录: |