Android back button and *ngIf


#1

Hello,

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 ?


#2

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.

https://docs.nativescript.org/core-concepts/application-lifecycle#android-activity-events

application.android.on(application.AndroidApplication.activityBackPressedEvent, function (args) {
        console.log("Event: " + args.eventName + ", Activity: " + args.activity);
        // Set args.cancel = true to cancel back navigation and do something custom.
    });

#3

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


#4

Sorry I wasn’t clear :sweat: I can handle back button, it seems more a problem about *ngIf directive.
I’ve found this issue https://github.com/NativeScript/nativescript-angular/issues/872 which is closer to my problem