Я хочу использовать APP_INITIALIZER
для загрузки информации о безопасности из бэкэнда, когда запускается угловое приложение. Я добавляю APP_INITIALIZER
в AppModule
:
providers: [
{
provide: APP_INITIALIZER,
useFactory: init,
deps: [AuthService],
multi: true
}
]
Моя функция инициализации:
export function init(authService: AuthService) {
return () => {
return authService.loadSecurityInfo(true).toPromise();
};
}
Метод loadSecurityInfo
выглядит так:
loadSecurityInfo(reconstituteSecurity = false): Observable<SecurityInfo> {
console.log(`Loading SecurityInfo - Reconstitute security? ${reconstituteSecurity}`);
return this.http
.get<any>(this.securityInfoUrl, {headers: this.headers})
.pipe(
map(body => {
this._securityInfo = new SecurityInfo();
this._securityInfo.isAuthenticationEnabled = body.authenticationEnabled;
this._securityInfo.isAuthenticated = body.authenticated;
this._securityInfo.username = body.username;
this._securityInfo.roles = body.roles as string[];
console.log(`Getting security info: ${JSON.stringify(this.securityInfo)}`);
return this._securityInfo;
}),
catchError(this.errorReporter.handleError('loadSecurityInfo', null))
);
}
Когда я запускаю приложение и пытаюсь обновить страницу, быстро нажимая F5, например, два раза, я получаю сообщение об ошибке в консоли браузера:
Http failure response for (unknown url): 0 Unknown Error
loadSecurityInfo failed: Backend returned code 0, status: undefined, error list: undefined
zUnb/Y</e.prototype.handleError/<
http://localhost:8080/main.ba74b710245ba9a3c361.js:1:1433305
9Z1F/u</t.prototype.error
m
http://localhost:8080/polyfills.855d06b353079dbdbf17.js:1:20756
b
Если я медленно нажму F5, когда предыдущее обновление страницы сработало, ошибки не будет! Я сломал свой мозг, почему происходит эта ошибка? Ошибка возникает , только , в Firefox browser 60.4.0 esr
возможна и ниже, на последних версиях Firefox
и Chrome
ошибок нет. Любая помощь.
Я использую Angular 6.1.10