angular - 控制台错误,因为端点无法访问且应用程序无法加载

标签 angular typescript

我已将 Angular 5 升级到 7 并保持 rxjs-compat。在这种情况下,应用程序运行良好,但后来我们删除了 rxjs-compat 并进行了相应的更改。我们在加载时遇到错误 在引导应用程序时将应用程序显示为“Enpoint unreachable”。 我们正在使用

"@ngx-config/core": "7.0.0",
"@ngx-config/http-loader": "7.0.0",

我怀疑这个包在升级后产生了一些问题。但是编译是成功的,只是在运行应用程序时它显示控制台错误作为端点无法访问。 任何其他人都遇到过这个问题或任何关于如何调试此类问题的想法。

任何帮助将不胜感激

编辑

进一步分析后发现,这个错误是因为@ngx-config更新导致的,与rxjs-compat无关。

// for config loader
export function configFactory(http: HttpClient): ConfigLoader {
  return new ConfigHttpLoader(http, environment.configFile);
} 

拦截器

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { 
//etc
})

最佳答案

我尝试了 github 和 SO 中提到的许多方法,但对我来说没有任何锻炼。我为让它发挥作用所做的最后一件事是,

在应用程序 Bootstrap 之前调用 main.ts 中的配置并在 session 存储中设置,您可以创建一个类文件并在那里执行您的逻辑。

const url = "configurl"// read from your environment file
const xmlHttp = new XMLHttpRequest();
      xmlHttp.onreadystatechange = () => {
        if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
          if (xmlHttp.responseText) {
            const config: any = JSON.parse(xmlHttp.responseText);
            if (config) {
             window.sessionStorage.setItem("config", JSON.stringify(config));

            }
        }
      };
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null); 

应用模块

export function configFactory(http: HttpClient): ConfigLoader {
  return new ConfigStaticLoader(JSON.parse(window.sessionStorage.getItem("config")));
} 

这对我来说很好。

最初的问题是,我无法同时使用配置加载器和 http 拦截器。

关于angular - 控制台错误,因为端点无法访问且应用程序无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54348073/

相关文章:

typescript - <AG-Grid> 类型 'children' 上不存在属性 'ColDef<object>'

Angular 4 + PrimeNG 菜单 - 多个菜单项显示为事件状态

jquery - 使用 PrimeNG 日历检测 [(ngmodel) 对所选日期的更改

javascript - 我可以使用 JavaScript 切换暗模式吗?

node.js - 避免类型 '{}' 不可分配给类型 'X'

javascript - 先按字母排序,再按数字排序

node.js - Electron 命令失败: npm prune --production

javascript - 无法确定字符串是否包含在我的 Angular 2 中的 Json 键中

angular - 将文档引用作为字段过滤

angular - 检查错误 'mat-expanded: true' 后 MatExpansionPanel 表达式已更改