以我app.component.ts
我调用一个函数从返回一个HTTP请求的结果的服务:@input变量被填充上的HTTP请求
questions: QuestionBase<any>[];
constructor(service: QuestionService) {
this.questions = service.getQuestions().subscribe(val => console.log(val)); //gets logged after the other console log below
}
在子组件此questions
阵列被进一步处理:
@Input() questions: QuestionBase<any>[] = [];
form: FormGroup;
constructor(private qcs: QuestionControlService) {}
ngOnInit() {
console.log("onInit", this.questions); //called before questions is filled
this.form = this.qcs.toFormGroup(this.questions);
}
我的问题是现在toFormGroup
函数ngOnInit
在HTTP请求尚未完成时调用得太早。我不习惯Observables。在getQuestions
中的HTTP请求完成后,我怎么能够调用该函数?我已经尝试过ngOnChanges
,但它在ngOnInit
之前甚至会被调用。
偏离主题中阵列不是空的,但你的猫太可爱了! @ AJT_82 – n00dl3
@ n00dl3哈哈,谢谢! :D她有一个姐姐,她也很可爱,因为被睁眼和几乎完全失明:P也许你看过这张照片,是我的最后一张个人照片..我以为她需要休息一下才能代表我:D http:///imgur.com/a/m2s0d – Alex