Android back button and *ngIf



I use different “views” on the same component with angular directive *ngIf. I switch views with a ‘previous’ button which is always present on the html component. When I click on the previous button it just changes a boolean that hide a layout and displays another one.
So I want to handle the android back button, because it goes back to previous component, not previous user’s view. I can register the back button event with success but when I’m asking to change the boolean it doesn’t change the UI accordingly.

any ideas ?



In Android the back button behavior can be controlled by it’s activity. Here you go how you can customize that adding a activityBackPressed listener., function (args) {
        console.log("Event: " + args.eventName + ", Activity: " + args.activity);
        // Set args.cancel = true to cancel back navigation and do something custom.


check this link i posted just find a way of using it in Angular
Android back button



Sorry I wasn’t clear :sweat: I can handle back button, it seems more a problem about *ngIf directive.
I’ve found this issue which is closer to my problem

1 Like