Angular Disable / Enable Back Button
Asked Answered
S

1

0

What I want to achieve is to disable and re-enable the back button at a certain moment of time. I used the following method to disable the back button:

disableBackButton() {
        history.pushState(null, null, location.href);
        this.locationStrategy.onPopState(() => {
          history.pushState(null, null, location.href);
        })
}

However, I don't know how to implement a function to "re-enable" the back button.

Surinam answered 25/5, 2021 at 5:59 Comment(5)
what is your html code? and when the button is going to be disabled?Segregationist
Let's assume I have a button that calls toggleEnableBackButton() that must disable/enable the button whenever it is clicked.Surinam
what is your html code... of button which you wanna disable..?Segregationist
The button I want to disable/enable is the browser back button and the button used to toggle between enable/disable is a basic button that looks like this <button (click)="toggleEnabled()">Toggle</button>Surinam
@ViorelOnica did you figureout answer to your question then please post answer?Siebert
S
0

Ok! take [disabled]="disabled==0" inside button html and define disabled:any property in ts file... then inside simply use

 this.disabled = 0; // when you want it to be disabled...
 this.disabled=1; // when you want it to be enabled...

in your function.

Segregationist answered 27/5, 2021 at 3:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.