在关闭插页广告后,Capacitor/Ionic 中的 Angular 无法在下一页检测到更改。

huangapple go评论108阅读模式
英文:

after close Interstitial ad then angular not able to detect changes on next page in capacitor/ionic

问题

Homepage.ts

// 所有导入部分
async ionViewWillEnter() {
    this.init();
    // this.zone.run(async () => {
    this.InterDish = await AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
      console.log("插屏广告已关闭");
      this.nextpage();
    });
    this.InterLoadFailh = await AdMob.addListener(InterstitialAdPluginEvents.FailedToShow, () => {
      console.log("插屏广告显示失败");
      this.nextpage();
    });
    // });
  }
ionViewWillLeave() {
    this.InterDish.remove();
    this.InterLoadFailh.remove();
}

nextpage.html

<ion-segment [(ngModel)]="Design" (ionChange)="segmentChanged($event)">
      <ion-segment-button value="new">
        新的
      </ion-segment-button>
      <ion-segment-button value="old">
        旧的
      </ion-segment-button>
      <ion-segment-button value="other">
        其他
      </ion-segment-button>
    </ion-segment>

当广告显示并关闭广告后,如果段落不改变,如果我添加以下代码this.cdr.detectChanges();,然后它才能检测到更改,如果广告未显示,则它正常工作。

英文:

Homepage.ts

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

  ionViewWillLeave() {
    this.InterDish.remove();
    this.InterLoadFailh.remove();
  }

nextpage.html

&lt;ion-segment [(ngModel)]=&quot;Design&quot; (ionChange)=&quot;segmentChanged($event)&quot;&gt;
      &lt;ion-segment-button value=&quot;new&quot;&gt;
        new
      &lt;/ion-segment-button&gt;
      &lt;ion-segment-button value=&quot;old&quot;&gt;
        old
      &lt;/ion-segment-button&gt;
      &lt;ion-segment-button value=&quot;other&quot;&gt;
        Other
      &lt;/ion-segment-button&gt;
    &lt;/ion-segment&gt;

when ads is disply and if i close the ad and on the "nextpage" segment not change, if i add write this
this.cdr.detectChanges(); code then only it detect change,
and if ad not display then it work correctly .

答案1

得分: 1

使用 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();
  })
});
英文:

use ngZone

import { NgZone } from &#39;@angular/core&#39;;

constructor(
   private zone: NgZone,    
) { }

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

huangapple
  • 本文由 发表于 2023年8月10日 17:02:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874183.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定