小编lur*_*ron的帖子

角量角器无头铬:使用APP_INITIALIZE时,在页面上找不到Angular

我们正在构建一个Ionic混合应用程序,并实施了由CI系统运行的自动化E2E测试。所有这些测试都一直正常工作,直到我们在“ app.module”中实现APP_INITIALIZE才能在初始化之前获取浏览器语言。

这是我们的APP_INITIALIZE实现的肮脏代码:

-app.module.ts

export function configurateLocaleData(dynamicRegisterLocaleService: DynamicRegisterLocaleService): () => Promise<any> {
    return () => dynamicRegisterLocaleService.configurateLocaleData();
}

...

providers: [

...


        {
            provide: APP_INITIALIZER, 
            useFactory: configurateLocaleData,
            deps: [ DynamicRegisterLocaleService ],
            multi: true
        }
...
Run Code Online (Sandbox Code Playgroud)

-dynamic-register-locale.service.ts

import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {AppConfig} from "../app.constants";
import {DateLocaleService} from "./dateLocale.service";
import {registerLocaleData} from "@angular/common";

@Injectable()
export class DynamicRegisterLocaleService {

    constructor(private httpClient: HttpClient) {
    }

    public configurateLocaleData(): Promise<any> {
        let currentLang = DateLocaleService.getLanguage();
        return this.httpClient.get("../assets/locales/" + currentLang + ".js", {responseType: …
Run Code Online (Sandbox Code Playgroud)

chromium headless-browser protractor ionic-framework angular

5
推荐指数
1
解决办法
500
查看次数