angular - Ionic 4 和带有网络电容器的 toastr 无法离线使用 PWA 应用程序

标签 angular typescript ionic4 progressive-web-apps capacitor

更新: 我已经更新了 Ionic 4.6.2(最新),它在离线模式下给出了以下异常。

Network status changed {connected: false, connectionType: "none"}connected: falseconnectionType: "none"__proto__: Object
bootstrap:145 GET http://localhost:8100/85.js net::ERR_INTERNET_DISCONNECTED
requireEnsure @ bootstrap:145
webpackAsyncContext @ .*\.entry\.js$ include: \.entry\.js$ exclude: \.system\.entry\.js$ namespace object:407
loadModule @ chunk-09ec7fc0.js:61
(anonymous) @ chunk-09ec7fc0.js:1468
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
initializeComponent @ chunk-09ec7fc0.js:1450
(anonymous) @ chunk-09ec7fc0.js:1604
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
(anonymous) @ zone.js:889
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
onScheduleTask @ zone.js:301
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:404
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
resolvePromise @ zone.js:825
(anonymous) @ zone.js:741
Promise.then (async)
(anonymous) @ zone.js:1092
ZoneAwarePromise @ zone.js:910
Ctor.then @ zone.js:1091
createOverlay @ chunk-d83bfeae.js:30
create @ chunk-d83bfeae.js:8
push../node_modules/@ionic/angular/dist/fesm5.js.OverlayBaseController.create @ fesm5.js:4874
(anonymous) @ show-toast.service.ts:13
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
push../src/app/services/utilities/show-toast.service.ts.ShowToastService.showNetworkStateErrorToast @ show-toast.service.ts:12
(anonymous) @ network-state-service.ts:40
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
onInvokeTask @ core.js:17290
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:422
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498
invokeTask @ zone.js:1744
globalZoneAwareCallback @ zone.js:1770
zone.js:682 Unhandled Promise rejection: Cannot read property 'isProxied' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'isProxied' of undefined
    at chunk-09ec7fc0.js:1476
    at step (tslib.es6.js:99)
    at Object.next (tslib.es6.js:80)
    at fulfilled (tslib.es6.js:70)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at zone.js:889
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601) TypeError: Cannot read property 'isProxied' of undefined
    at http://localhost:8100/vendor.js:87541:27
    at step (http://localhost:8100/vendor.js:112070:23)
    at Object.next (http://localhost:8100/vendor.js:112051:53)
    at fulfilled (http://localhost:8100/vendor.js:112041:58)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:8100/polyfills.js:2753:26)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost:8100/polyfills.js:2512:43)
    at http://localhost:8100/polyfills.js:3251:34
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:2785:31)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:8100/polyfills.js:2557:47)
    at drainMicroTaskQueue (http://localhost:8100/polyfills.js:2963:35)

如何使用 Network capacito r 与 Ionic 4?当我进行调试时,我可以正确地看到执行情况。但是toast不起作用。

这个我已经试过了。但它不起作用。

注意:实际上网络电容器工作正常。但它没有显示toast。我已经在浏览器和 firebase 托管(即 https)上对此进行了测试

service.ts

 async WatchConnection() {
    this.networkListener = Network.addListener('networkStatusChange', (status) => {
      this.networkStatus = status;
      if (!this.networkStatus.connected) {
        this.showToastService.showNetworkStateErrorToast('Your internet seems to be down! Please check your network settings!');
      } else {
        setTimeout(() => {
          this.showToastService.toast.dismiss();
          if (this.networkStatus.connected) {
            this.showToastService.showNetworkStateSuccessToast('Internet connection available!');
          }
        }, 3000);
      }
    });

    this.networkStatus = await Network.getStatus();
  }

app.component.ts

 async initializeApp() {
    this.networkStateService.WatchConnection();
  }

最佳答案

我发现了一个 hack,直到 Ionic 团队修复这个问题。

Toast 服务内部:

 constructor(private toastCtrl: ToastController, ) {
    this.toastCtrl.create({ animated: false }).then(t => { t.present(); t.dismiss(); });
  }

关于angular - Ionic 4 和带有网络电容器的 toastr 无法离线使用 PWA 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57164430/

相关文章:

firebase - ios 上的 ionic firebase 手机身份验证无需重新验证

ionic-framework - 我们可以自定义 ionic toast 关闭按钮吗?

javascript - 错误 TS2339 : Property 'access_token' does not exist angular 2

angular - 在 httpInterceptor 中过滤请求 - Angular 4.3+

Angular 5 文件保存程序将 CSV 文件编码为 ANSI

reactjs - 使用 TypeScript 为 React 高阶组件输入注解

angular - 如何检查可观察的倒数计时器是否已完成?

angular - 区分 ionic <ion-toggle> 中的用户事件与模型更改

javascript - 有没有办法以编程方式更改激活的 mat-tab?

ionic-framework - 是否可以设置 ion-img 类的样式?