Dies ist mein Code und ich konnte keine Lösung für mein Problem finden. Es tut mir leid, wenn die Antwort irgendwo existiert und nicht gefunden werden konnte.angular 2 rc - Eigenschaft 'Anfrage' von undefined nicht lesen
Dies ist die app.component.ts
import {Component} from '@angular/core';
import { HTTP_PROVIDERS} from '@angular/http';
import {SimpleHTTPComponent} from './simplehttp'
@Component({
selector: 'my-app',
providers: [HTTP_PROVIDERS],
template: `
<div>
<simple-http></simple-http>
</div>
`,
directives: [SimpleHTTPComponent]
})
export class AppComponent {
\t
\t data: Object;
\t loading: boolean;
\t constructor() {
\t }
}
Das ist mein simplehttp.ts Datei
import {Component} from '@angular/core';
import {Http, Response} from '@angular/http';
import { HTTP_PROVIDERS } from '@angular/http';
import {Inject} from '@angular/core'
@Component({
selector: 'simple-http',
template: `
\t <h2>Basic Request</h2>
\t <button type="button" (click)="makeRequest()">Make Request</button>
\t <div *ngIf="loading">loading...</div>
\t <pre>{{data | json}}</pre>`,
providers:[HTTP_PROVIDERS]
})
export class SimpleHTTPComponent {
\t data: Object;
\t loading: boolean;
\t http: Http;
\t constructor(@Inject(Http) private _http: Http){
\t \t
\t }
\t makeRequest():void{
\t \t this.loading = true;
\t \t this.http.request('http://jsonplaceholder.typicode.com/posts/1')
\t \t .subscribe((res: Response) => {
\t \t this.data = res.json();
\t \t this.loading = false;
\t \t });
\t }
}
Sie sind schnell, ich war im Begriff, die gleiche Antwort zu schreiben. + 1 von mir :) –
Der frühe Vogel bekommt den Wurm ;-) –
Danke, ich weiß, dass ich irgendwo dumme Fehler gemacht habe. – edaddou