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

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

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

问题

Homepage.ts

  1. // 所有导入部分
  2. async ionViewWillEnter() {
  3. this.init();
  4. // this.zone.run(async () => {
  5. this.InterDish = await AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
  6. console.log("插屏广告已关闭");
  7. this.nextpage();
  8. });
  9. this.InterLoadFailh = await AdMob.addListener(InterstitialAdPluginEvents.FailedToShow, () => {
  10. console.log("插屏广告显示失败");
  11. this.nextpage();
  12. });
  13. // });
  14. }
  1. ionViewWillLeave() {
  2. this.InterDish.remove();
  3. this.InterLoadFailh.remove();
  4. }

nextpage.html

  1. <ion-segment [(ngModel)]="Design" (ionChange)="segmentChanged($event)">
  2. <ion-segment-button value="new">
  3. 新的
  4. </ion-segment-button>
  5. <ion-segment-button value="old">
  6. 旧的
  7. </ion-segment-button>
  8. <ion-segment-button value="other">
  9. 其他
  10. </ion-segment-button>
  11. </ion-segment>

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

英文:

Homepage.ts

  1. //all imports
  2. async ionViewWillEnter() {
  3. this.init();
  4. // this.zone.run(async () =&gt; {
  5. this.InterDish = await AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () =&gt; {
  6. console.log(&quot;Interstitial Dismissed&quot;);
  7. this.nextpage();
  8. });
  9. this.InterLoadFailh = await AdMob.addListener(InterstitialAdPluginEvents.FailedToShow, () =&gt; {
  10. console.log(&quot;Iterstitial FailedToShow&quot;);
  11. this.nextpage();
  12. });
  13. // });
  14. }
  1. ionViewWillLeave() {
  2. this.InterDish.remove();
  3. this.InterLoadFailh.remove();
  4. }

nextpage.html

  1. &lt;ion-segment [(ngModel)]=&quot;Design&quot; (ionChange)=&quot;segmentChanged($event)&quot;&gt;
  2. &lt;ion-segment-button value=&quot;new&quot;&gt;
  3. new
  4. &lt;/ion-segment-button&gt;
  5. &lt;ion-segment-button value=&quot;old&quot;&gt;
  6. old
  7. &lt;/ion-segment-button&gt;
  8. &lt;ion-segment-button value=&quot;other&quot;&gt;
  9. Other
  10. &lt;/ion-segment-button&gt;
  11. &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

  1. import { NgZone } from '@angular/core';
  2. constructor(
  3. private zone: NgZone,
  4. ) { }
  5. this.InterDish = AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
  6. this.zone.run(() => {
  7. console.log("Interstitial Dismissed");
  8. this.nextpage();
  9. })
  10. });
英文:

use ngZone

  1. import { NgZone } from &#39;@angular/core&#39;;
  2. constructor(
  3. private zone: NgZone,
  4. ) { }
  5. this.InterDish = AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () =&gt; {
  6. this.zone.run(() =&gt; {
  7. console.log(&quot;Interstitial Dismissed&quot;);
  8. this.nextpage();
  9. })
  10. });

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:

确定