import { IonBackButtonDelegate } from '@ionic/angular'
class TestButton {
@ViewChild('backbutton') backButtonDelegate: IonBackButtonDelegate
this.backButtonDelegate.onClick = (en: Event) => {
console.log("test")
}
}
我想更改“ ion-back-buttom”的默认功能,但似乎没有用,有人可以帮忙吗?非常感谢。
答案 0 :(得分:0)
您可以这样做。但是,该事件不会触发android物理后退按钮的点击。
在模板中:
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button (click)="back()">
<ion-icon name="arrow-back"></ion-icon>
</ion-button>
</ion-buttons>
<ion-title>Title</ion-title>
</ion-toolbar>
</ion-header>
在组件中:
back() {
// Do what you want here
}
答案 1 :(得分:0)
您选择的错误。这应该工作-
import { IonBackButtonDelegate } from '@ionic/angular'
class TestButton {
@ViewChild(IonBackButtonDelegate, { static: false }) backButtonDelegate: IonBackButtonDelegate;
this.backButtonDelegate.onClick = (en: Event) => {
console.log("test")
}
}