1
В настоящее время я пытаюсь разобраться в Угловом 2, и у меня возникают проблемы с отображением данных, возвращенных из созданной службы. В инструментах разработчика я вижу стрельбу api api, но я никогда не вижу никаких данных, отображаемых в представлении. Есть идеи? Мне что-то не хватает?Угловой 2, Получение данных не обслуживается
SubjectService.tsimport {Injectable} from "angular2/core";
import {Http, Response, HTTP_PROVIDERS} from "angular2/http";
@Injectable()
export class SubjectService{
constructor(public http: Http){
}
getSubject(){
return this.http.request('/subjects.json')
.map(response => response.json())
.subscribe(
res => this.subjects = res,
err => this.logError(err)
);
}
}
DashboardComponent.ts
import { Component, View } from 'angular2/core'
import { CORE_DIRECTIVES } from "angular2/common"
import {SubjectService} from "../../services/subject/SubjectService.ts"
import 'rxjs/add/operator/map';
@Component({
selector: 'dashboard',
providers: [SubjectService]
})
@View({
template: `
<div class="row">
<div class="medium-12 columns">
<h1>Dashboard!</h1>
{{subjects}}
</div>
</div>
`
})
export class DashboardComponent{
constructor(subjectService: SubjectService){
subjectService.getSubject()
}
}