【发布时间】:2017-08-02 00:27:24
【问题描述】:
export class PersonEditDetailsComponent implements OnInit,OnDestroy {
person: Person;
sub: any;
constructor(private peopleService: PeopleService,
private route: ActivatedRoute,
private router: Router) {
}
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
let id = Number.parseInt(params['id']);
console.log('getting person with id: ', id);
this.peopleService
.get(id) // send http request
.subscribe(response => this.person = response); // get response value
});
}
//I want to access this.person values here.
}
我是 Angular2 JS 的新手。如上代码,我只想将 json 响应数据映射到 angular2 typescript 对象。我怎样才能做到这一点。它正在获得“响应”价值。但不能映射到人对象。我想使用来自外部的响应数据
【问题讨论】:
-
你能在这里分享你的 JSON 响应吗!
-
从外部访问它外部是什么意思?
-
ngOnInit() 方法范围之外
标签: javascript json http angular typescript