英文:
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 () => {
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>
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 '@angular/core';
constructor(
private zone: NgZone,
) { }
this.InterDish = AdMob.addListener(InterstitialAdPluginEvents.Dismissed, () => {
this.zone.run(() => {
console.log("Interstitial Dismissed");
this.nextpage();
})
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论