I want to retrieve a list of objects "listOfArticles" from the back before to call next methods which initialize form and use validators on this list. But in my case, the form is initialized before the end of http request (because of asynchronous method). How to fix it ?
Method of managementArbo.service.ts :
constructor(private http: Http) { }
getProducts(parametres :string) :Observable<any> {
console.log("Dans getProducts avec "+parametres);
let url :string = "http://#####"+parametres;
let observable :Observable<any> = this.http.get(url).map((res:Response) => res.json());
return observable;
}
ngOnInit() method of myForm.ts
ngOnInit() {
this.getListBdd();
this.myFormGroup = this.fb.group({
itemRows: this.fb.array([this.initItemRows()])
})
}
getListBdd() method of myForm.ts
public getListBdd() {
this.route.params.subscribe((params: Params) => {
let subroute = "getRefNumber";
this.managementArbo.getProducts(subroute)
.subscribe(
res => { this.listOfArticles = res; console.log('bdd:' + res); }
,
err => console.log(err),
() => console.log('getProducts done'));
});
}
subscribecallback