【问题标题】:Nativescript-Angular handling back button to change vizibilityNativescript-Angular 处理后退按钮以更改可见性
【发布时间】:2020-07-14 07:08:46
【问题描述】:

我正在尝试更改后退按钮事件中元素的可见性。

 <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;
        });          
}         

变量变为假,但元素没有隐藏。

【问题讨论】:

    标签: angular nativescript nativescript-angular


    【解决方案1】:

    您有时需要告诉 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();
            });          
    }   
    

    【讨论】:

      猜你喜欢
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多