晚上好,小伙子们angular2 HTTP决心承诺
我试图进入angular2并得到了让我从正在进行的一个问题。
服务:
getProject(id: number): any {
var url = this.ProjectsUrl + '/'+ id;
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response.json().data as Project);
})
.catch(this.handleError);
}
组件:
getProject(id:number){
this.projectService
.getProject(id)
.then(project => this.project = project);
}
ngOnInit()
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.getCustomers();
console.log('b4 getProj')
this.getProject(+params["id"]);
console.log('after getProj')
});
}
输出:
b4 getProj
after getProj
Object { Project }
我不知道为什么诺言不会得到解决?有小费吗?
为什么你觉得有什么不得到解决? –