首页 > 解决方案 > 角度模块中的条件提供程序引发 AOT 错误

问题描述

仅当浏览器是 IE 时,我才想将提供程序推送到我的提供程序列表中。

我试过了

 const IE = detectIE();
    providers: [abcService,
      xyzService,
      (IE) ? [{provide: EVENT_MANAGER_PLUGINS,
        useClass: IeInputEventManagerService,
        deps: [DOCUMENT],
        multi: true
    }] : [],

上面的代码抛出 AOT 错误,说装饰器中不允许使用符号。我也试过如下

const IE = detectIE();
const tempProviders: Array<any> = [
  abcService,
  xyzService];

if(IE) {
tempProviders.push({provide: EVENT_MANAGER_PLUGINS,
    useClass: IeInputEventManagerService,
    deps: [DOCUMENT],
    multi: true
});
}

@NgModule -> continues here

在上述情况下,提供者永远不会被推送或永远不会被激活。我该如何解决这个问题?

标签: angularangular-moduleangular-providersangular-aot

解决方案


推荐阅读