Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Http requests in universal mode #7

Closed
@jtheoof

Description

@jtheoof

This is not really an issue, more of a noob's question. How to perform http requests in universal mode.
I'm trying to follow the current documentation.

app.ts:

import {Component} from 'angular2/angular2';
import {Http, HTTP_PROVIDERS} from 'angular2/http';

@Component({
    selector: 'app',
    viewProviders: [HTTP_PROVIDERS],
    template: `
    <div>
        <h1>Hello, {{ name }}!</h1>
    </div>
    `
})
export class App {
    public people: any;
    constructor(http: Http) {
        http.get('people.json').map((res: any) => res.json()).subscribe((people: any) =>
            this.people = people
        );
    }
}

But the code is actually run in the server, and therefore nodejs is unhappy of XMLHttpRequest not being present (which is normal since running this code by the universal bootstrap).

ReferenceError: XMLHttpRequest is not defined
    at BrowserXhr.build (app/node_modules/angular2/src/http/backends/browser_xhr.js:17:60)
    at Observable._subscribe (app/node_modules/angular2/src/http/backends/xhr_backend.js:34:35)
    at Observable._subscribe (app/node_modules/angular2/node_modules/@reactivex/rxjs/dist/cjs/Observable.js:134:28)
    at Observable.subscribe (app/node_modules/angular2/node_modules/@reactivex/rxjs/dist/cjs/Observable.js:103:29)
    at new App (app/built/client/app.js:15:78)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions