首页 文章

像在IOS中一样更改离子后退按钮文本

提问于
浏览
1

我想用以前的页面视图名称更改离子后退按钮文本,就像在iPhone中一样 . 如果它从 Users 导航到 User detail ,我希望在用户详细信息页面视图中将后退文本更改为 Users .

目前,这是我从浏览解决方案中获得的 .

imports: [
    IonicModule.forRoot(MyApp, {
      tabsPlacement: 'top',
      backButtonText: 'Back',
      iconMode: 'ios',
      modalEnter: 'modal-slide-in',
      modalLeave: 'modal-slide-out',
      tabbarPlacement: 'bottom',
      pageTransition: 'ios'
     })
  ]

这将更改默认值 . 如何以编程方式从堆栈中更改页面名称的 backButtonText 值 .

1 回答

  • 2

    要动态更改后退按钮文本,可以使用 ViewContoller.setBackButtonText() 方法 . 见:https://ionicframework.com/docs/api/navigation/ViewController/

    要获得上一页 Headers ,您应该查找 NavController.last() 可以为您提供的内容 .

    将ViewController注入组件 .

    import { ViewController } from 'ionic-angular';
    constructor(private viewController: ViewController) {}
    

    然后,您需要在加载DOM之后发生的组件生命周期事件中设置文本:

    ionViewDidLoad() {
        this.viewController.setBackButtonText('My Back Button Text');
    }
    

    请参阅Ionic "Lifecycle events" doc以找到符合您需求的产品 . https://ionicframework.com/docs/api/navigation/NavController/

    我将所有代码信用(并谢谢)给以下答案的绅士:https://stackoverflow.com/a/42013787/1321664

相关问题