Inject Http manually in Angular 4

前端 未结 4 1179
一整个雨季
一整个雨季 2020-12-03 16:36

I want to manually bootstrap an Angular 4 app (created with CLI). In main.ts I am doing this:

const injector = ReflectiveInjector.resolveAndCrea         


        
4条回答
  •  情书的邮戳
    2020-12-03 17:07

    Thanks, Kuncevic. I have come up with this solution, which works fine:

    function httpGetAsync(theUrl, callback) {
      const xmlHttp = new XMLHttpRequest();
    
      xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
          callback(xmlHttp.responseText);
        }
      }
    
      xmlHttp.open('GET', theUrl, true); // true for asynchronous
      xmlHttp.send(null);
    }
    
    httpGetAsync('assets/configs/configuration.json', (config: string) => {
      ConfigurationService.configuration = JSON.parse(config);
      platformBrowserDynamic().bootstrapModule(AppModule);
    });
    

提交回复
热议问题