Я пытаюсь этот код в Angular2 бета 15.Angular2 http.get код не работает
import {Component} from 'angular2/core';
import {Http, Response} from 'angular2/http';
@Component({
selector: 'my-app',
template: `
<h2>Basic Request</h2>
<button type="button" (click)="makeRequest()">Make Request</button>
<div *ngIf="loading">loading...</div>
<pre>{{data.title}}</pre>
`
})
export class AppComponent {
data: any;
loading: boolean;
constructor(public http: Http) {
}
makeRequest(): void {
this.loading = true;
this.http.get('http://jsonplaceholder.typicode.com/photos/1')
.map((res: Response) => res.json())
.subscribe(res => {
this.data = res;
this.loading = false;
});
}
}
По какой-то причине он получает данные, но не отображает его.
Что мне здесь не хватает?
Неправильно ли обновляется свойство 'loading'? –
Он просто говорит Загрузка ... и ответ пуст – Satch3000