首页 > 解决方案 > 装饰器不支持函数调用,但调用了“NgForageModule”

问题描述

升级到 Angular 7 后,我无法使用 AOT(使用 Ionic)创建构建。

我跑ionic cordova build android得到

ERROR in Error during template compile of 'AppModule'
  Function calls are not supported in decorators but 'NgForageModule' was called.

app.module.ts:

import {NgForageModule, Driver} from 'ngforage';

...

imports: [
    NgForageModule.forRoot({
      name: 'next-storage',
      driver: [
        Driver.INDEXED_DB,
        Driver.WEB_SQL,
        Driver.LOCAL_STORAGE
      ]
    }),
    ...
]
...

标签: angular

解决方案


我必须使用DEFAULT_CONFIG提供的并将我的自定义配置importsproviders.

变化app.module.ts

import {Driver, NgForageOptions, DEFAULT_CONFIG} from 'ngforage';

...

const ngfRootOptions:NgForageOptions = {
  name: 'next-storage',
  driver: [
    Driver.INDEXED_DB,
    Driver.WEB_SQL,
    Driver.LOCAL_STORAGE
  ]
};

...

providers: [
    {
      provide:  DEFAULT_CONFIG,
      useValue: ngfRootOptions
    }
    ...
]
...

推荐阅读