My template is:

<ActionBar class="action-bar">
    <NavigationButton android.systemIcon="ic_menu_back" text="Back" (tap)="goBack()"></NavigationButton>
</ActionBar>

How to write function goBack() to move back?

1 Answers

2
Ian MacDonald On Best Solutions

Since you're using Angular, you can use RouterExtensions from the nativescript-angular package. Specifically, call routerExtensions.back(). Here's a complete inline example:

import { Component } from '@angular/core';
import { RouterExtensions } from 'nativescript-angular/router';

@Component({
    selector: 'example',
    moduleId: module.id,
    template: `<ActionBar class="action-bar">
    <NavigationButton android.systemIcon="ic_menu_back" text="Back" (tap)="routerExtensions.back()"></NavigationButton>
</ActionBar>`,
})
export class ExampleComponent {
    constructor(public routerExtensions: RouterExtensions) {
    }
}