Nativescript-Angular 处理后退按钮以更改可见性
Nativescript-Angular handling back button to change vizibility
我正在尝试更改元素在后退按钮事件中的可见性。
<ActionItem icon="~/images/menu_3_dots.png" ios.position="right" android.position="right" *ngIf="isActionItemVisible"></ActionItem>
constructor(private router: Router, private page: Page) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args: any) => {
args.cancel = true;
console.log("Is backbutton pressed !");
this.isActionItemVisible= false;
});
}
变量变为false但元素没有隐藏。
您有时需要告诉 angular 执行检测周期以应用更改:
constructor(private router: Router, private page: Page, private cdr: Change
DetectionRef) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args: any) => {
args.cancel = true;
console.log("Is backbutton pressed !");
this.isActionItemVisible= false;
this.cdr.detectChanges();
});
}
我正在尝试更改元素在后退按钮事件中的可见性。
<ActionItem icon="~/images/menu_3_dots.png" ios.position="right" android.position="right" *ngIf="isActionItemVisible"></ActionItem>
constructor(private router: Router, private page: Page) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args: any) => {
args.cancel = true;
console.log("Is backbutton pressed !");
this.isActionItemVisible= false;
});
}
变量变为false但元素没有隐藏。
您有时需要告诉 angular 执行检测周期以应用更改:
constructor(private router: Router, private page: Page, private cdr: Change
DetectionRef) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args: any) => {
args.cancel = true;
console.log("Is backbutton pressed !");
this.isActionItemVisible= false;
this.cdr.detectChanges();
});
}