Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the back button title in ionic framework?

In Ionic Framework, I use this HTML structure on all my views:

 <ion-view view-title="Some title">
    <ion-nav-buttons>
    </ion-nav-buttons>
 <ion-content>

Then I get a "< Back" button generated automatically. However, sometimes this button has the word "Back" and sometimes it has the name of the previous view.

Where and how can I change how the back button title behaves?

like image 472
Weblurk Avatar asked Aug 19 '15 06:08

Weblurk


People also ask

How do I change the title of my Ionic app?

html" file in the src folder. You would see the "title" html tag. Change it there and it would reflect.

How does Ionic handle back button?

Hardware Back Button in Capacitor and Cordova​The @capacitor/app package must be installed in Capacitor apps to use the hardware back button. When running in a Capacitor or Cordova application, Ionic Framework will emit an ionBackButton event when a user presses the hardware back button.

How do I change the menu icon in Ionic?

To define a custom asset for our ion-icon is as easy as just passing the path of our file in the src property. Now copy and paste the XML below into the custom-menu. svg . The cool part is that using this technique it's possible to customize the theme by just adding the color attribute in the ion-menu-button .

How do you change the color of an ion title?

You can change the background color of the toolbar with the standard title by setting the --background CSS variable on ion-toolbar . This will give the effect of the header changing color as you collapse the large title.


2 Answers

You should use the $ionicConfigProvider:

var myApp = angular.module('reallyCoolApp', ['ionic']);

myApp.config(function($ionicConfigProvider) {
  $ionicConfigProvider.views.maxCache(5);

  // note that you can also chain configs
  $ionicConfigProvider.backButton.text('Go Back');
});

This example is from the official Ionic docs.

To control the behaviour of the "last view text on back button" you could set backButton.previousTitleText(value) to false.

like image 167
m1crdy Avatar answered Oct 08 '22 20:10

m1crdy


In Ionic Framework 2 you could now use the set the config property backButtonText to ''

@NgModule({
  declarations: [ MyApp ],
  imports: [
    IonicModule.forRoot(MyApp, {
      backButtonText: '',
    }, {}
  )],
  bootstrap: [IonicApp],
  entryComponents: [ MyApp ],
  providers: []
})
like image 3
0x1ad2 Avatar answered Oct 08 '22 19:10

0x1ad2