Angular 5:未处理的承诺拒绝:无法加载html文件

问题描述 投票:1回答:1

我对Angular 5有一个问题。我正在尝试使用aot在ng服务==>("start": "ng serve --ssl --aot"文件中的package.json)中以生产模式运行我的应用程序。但是,在这种情况下,应用程序找不到html文件。它没有aot工作。我尝试了几个解决方案(提到herehere),比如在这些文件中的templateUrl字段中更改文件路径(例如,绝对路径)或更改应用程序路由或添加moduleId: module.id,但它们不起作用。看到以下错误:

enter image description here

任何的想法?

angular angular2-aot angular-aot
1个回答
1
投票

我的一个项目中有类似的问题。

对我来说问题是我在一个不同的文件中引导我的应用程序(我们有关于用户何时可以登录的要求,我们不想加载应用程序,如果他们不能)。

它与Angular 4一起使用,当我们升级到Angular 5时,我们得到了错误。

我们有类似的东西:

const hack = false;
if (hack) {
  platformBrowserDynamic().bootstrapModule(AppModule);
}

const bootstrap = new Bootstrap(AppModule);
bootstrap.initializeBootstrap();

我们传入了我们的模块,让bootstrap文件完成其余的工作。我们这样做是因为在Angular 4中有一个错误,它不允许引导代码在另一个文件或promise中,请参阅以下内容:

https://github.com/angular/angular-cli/issues/3540

Angular 4.0.0 could not find bootstrap code

在升级到Angular 5后,将其改为承诺似乎解决了这个问题。

const bootstrap = new Bootstrap();
bootstrap.initializeBootstrap().then(() => {
  console.log('user is allowed to see, bootstrap the app');
  platformBrowserDynamic().bootstrapModule(AppModule);
}, (error) => {
  console.log('user is not allowed access do something here', error);
});

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.