本文介绍了如何在ionic 4中预取(+预加载)特定模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

preloadingStrategy设置为PreloadAllModules时,我的应用程序正在提取我创建的所有模块/组件.但是我不确定该应用程序是否还在获取Ionic的所有模块/组件.

When preloadingStrategy is set to PreloadAllModules, my app is fetching all modules/components that I have created. But I am not sure if the app is also fetching all modules/components of Ionic.

实际上,当应用程序处于脱机状态时,当用户执行某些操作时,我需要显示一个错误模态.但是在离线模式下,尽管我自己的组件和路由都可以正常工作,但Ionic组件均无法正常工作(因为它们没有预先加载).

Actually, I need to show an error Modal, when the user is performing some action, while the app is offline. But in offline mode, none of the Ionic components work (since they are not preloaded), though my own components and routes are working fine.

所以我需要知道如何预加载Ionic的特定模块/组件?就我而言ModalController

So I need to know how to preload a specific module/component of Ionic? In my case ModalController

错误如下:

  1. 获取 http://localhost:8100/40.js net :: ERR_INTERNET_DISCONNECTED"
  2. core-ca0488fc.js:63 ChunkLoadError:加载块40失败.(错误: http://localhost:8100/40.js )at requireEnsure( http://localhost:8100/runtime.js:127:26 )在Array.map()在webpackAsyncContext( http://localhost:8100/main.js:425:34 )在loadModule( http://localhost:8100/vendor.js:167829:166 )在initializeComponent( http://localhost:8100/vendor.js:169460:20 )在 http://localhost:8100/vendor.js:169601:32 在ZoneDelegate.invoke( http://localhost:8100/polyfills.js:3594:26 )在Zone.run( http://localhost:8100/polyfills.js:3359:43 )在 http://localhost:8100/polyfills.js:4090:36 在ZoneDelegate.invokeTask( http://localhost:8100/polyfills.js:3626:31 )
  1. "GET http://localhost:8100/40.js net::ERR_INTERNET_DISCONNECTED"
  2. core-ca0488fc.js:63 ChunkLoadError: Loading chunk 40 failed.(error: http://localhost:8100/40.js)at requireEnsure (http://localhost:8100/runtime.js:127:26)at Array.map ()at webpackAsyncContext (http://localhost:8100/main.js:425:34)at loadModule (http://localhost:8100/vendor.js:167829:166)at initializeComponent (http://localhost:8100/vendor.js:169460:20)at http://localhost:8100/vendor.js:169601:32at ZoneDelegate.invoke (http://localhost:8100/polyfills.js:3594:26)at Zone.run (http://localhost:8100/polyfills.js:3359:43)at http://localhost:8100/polyfills.js:4090:36at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3626:31)

推荐答案

我使用了自定义的PreloadService,它直接在其构造函数中启动了伪模态:

I've used custom PreloadService which initiate fake modal directly in it constructor:

@Component({
  template: '<div></div>'
})
class StubComponent {}

@Injectable({
  provideIn: 'root'
})
export class PreloadIonicComponentService {
  constructor(private modalCtrl: ModalController) {
    modalCtrl.create({
     component: StubComponent
    }).then(m => m.dismiss());
  }
}

然后我在app.component.ts的构造函数参数中使用了此服务.结果,构建系统会将模式控制器和相关内容打包到主捆绑包中.

Then I've used this service in my app.component.ts's constructor arguments. As a result build system will pack modal controller and related stuff into the main bundle.

PS:另外,我把AlertController和ActionSheetController放在那儿.

PS: Also, I put there AlertController and ActionSheetController.

这篇关于如何在ionic 4中预取(+预加载)特定模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 00:59