Ionic 关闭后间隙广告,然后Angular 无法检测电容器/离子下一页的变化

c90pui9n  于 2023-09-28  发布在  Ionic
关注(0)|答案(1)|浏览(154)

Homepage.ts

//all imports 
 async ionViewWillEnter() {
    this.init();
    // this.zone.run(async () => {
    this.InterDish = await AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
      console.log("Interstitial Dismissed");
      this.nextpage();
    });
    this.InterLoadFailh = await AdMob.addListener(InterstitialAdPluginEvents.FailedToShow, () => {
      console.log("Iterstitial FailedToShow");
      this.nextpage();
    });
    // });
  }
ionViewWillLeave() {
    this.InterDish.remove();
    this.InterLoadFailh.remove();
  }

nextpage.html

<ion-segment [(ngModel)]="Design" (ionChange)="segmentChanged($event)">
      <ion-segment-button value="new">
        new
      </ion-segment-button>
      <ion-segment-button value="old">
        old
      </ion-segment-button>
      <ion-segment-button value="other">
        Other
      </ion-segment-button>
    </ion-segment>

当广告显示,如果我关闭广告,并在“下一页”段没有改变,如果我添加写这个this.cdr.detectChanges();代码,那么只有它检测到变化,如果广告不显示,那么它工作正常。

a11xaf1n

a11xaf1n1#

使用ngZone

import { NgZone } from '@angular/core';

constructor(
   private zone: NgZone,    
) { }

this.InterDish = AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
  this.zone.run(() => {
     console.log("Interstitial Dismissed");
     this.nextpage();
  })
});

相关问题