Ich versuche, einen REST-API-Aufruf zu meinem anderen lokalen Host-Server zu machen, ich habe diesen Dienst gemacht:http definiert mich nicht in angular2
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {GlobalService} from '../app.service';
@Injectable()
export class AuthenticationService {
constructor(private _globals: GlobalService) {}
constructor(private _http: Http) {}
globals = this._globals.getGlobals()
getAuthenticationData() {
this._http.get(globals.apiURL)
}
}
Und es in meiner Komponente Aufruf:
import { Component } from 'angular2/core';
import {AuthenticationService} from '../services/authentication.service';
@Component({
selector: 'wd-header';
templateUrl: 'app/templates/header.html'
providers: [AuthenticationService]
})
export class HeaderComponent {
constructor(private _authenticationService: AuthenticationService) {}
authentication = this._authenticationService.getAuthenticationData()
}
Aus irgendeinem Grund aber, Angular Ansprüche, die Http nicht definiert ist:
EXCEPTION: Error during instantiation of HeaderComponent!. angular2.dev.js:22911:9
ORIGINAL EXCEPTION: TypeError: this._http is undefined
Was mache ich falsch?
bearbeiten schließen main.ts:
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import {App} from './app.component';
import {GlobalService} from './app.service';
bootstrap(App, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
GlobalService
]);
@pixelbits Ja. –
Wird die Datei 'http.dev.js' in Ihrer' index.html' referenziert? – Brad