Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Http service throws error 'XMLHttpRequest is not defined' #14

Open
mcgraphix opened this issue Apr 13, 2016 · 0 comments
Open

Http service throws error 'XMLHttpRequest is not defined' #14

mcgraphix opened this issue Apr 13, 2016 · 0 comments

Comments

@mcgraphix
Copy link

I am trying to build an app that hits a particular server and displays the data. When injecting and using the Http service I get an error a mile long. The gist of it is:

EXCEPTION: Error during instantiation of App!.
ORIGINAL EXCEPTION: ReferenceError: XMLHttpRequest is not defined
ORIGINAL STACKTRACE:
ReferenceError: XMLHttpRequest is not defined
    at BrowserXhr.build (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/http/backends/browser_xhr.js:19:60)
    at Observable._subscribe (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/http/backends/xhr_backend.js:32:35)
    at Observable.subscribe (/Users/mckeowr/Documents/git/angular-electron/node_modules/rxjs/Observable.js:58:33)
    at new App (/Users/mckeowr/Documents/git/angular-electron/demo/component.js:17:14)
    at /Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/reflection/reflection_capabilities.js:13:47
    at Injector._instantiate (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/di/injector.js:777:27)
    at Injector._instantiateProvider (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/di/injector.js:715:25)
    at Injector._new (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/di/injector.js:704:21)
    at InjectorInlineStrategy.instantiateProvider (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/di/injector.js:204:30)
    at ElementDirectiveInlineStrategy.init (/Users/mckeowr/Documents/git/angular-electron/node_modules/angular2/src/core/linker/element.js:558:24)

I started from the demo code and just changed the "component.ts" file as shown here:

import {Component, ElementRef, Inject, Injectable} from 'angular2/core';
import {HTTP_PROVIDERS, Http} from 'angular2/http';

@Component({
    selector: 'app',
    template: `<div><h1>Hello World</h1></div>`,
    providers: [
    HTTP_PROVIDERS
    ]
})
@Injectable()
export class App {
    constructor(private Http:Http){

        this.Http.get('http://localhost:3000')
                .subscribe((response) => {
                    alert(response);
                });

    }
}

It seems that maybe the code is running in the main process and not the renderer process which results in a problem with browser_xhr?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant