forum subscription

Wanna help programmers by answering latest Angular questions?

We will email you whenever a new question is posted in Angular section. Max 2 emails per week.

Primeng dynamic form dropdown (DynamicSelectModel) set data problem

Hi,
http://ng2-dynamic-forms.udos86.de/sample/index.aot.html#/primeng-sample-form Here I am using dynamic form.

dynamicSelectModelBirims: SelectModel[] = [];


export class SelectModel {
label: string;
value: any;
}
constructor(private formService: DynamicFormService, private helperService: HelperService,
private birimlerService: BirimlerService) {


setTimeout(() => {
this.dynamicFormCreate();
this.formGroupValue = this.formService.createFormGroup(this.formModel);

}, 100);
// this.getBirims();
setTimeout(() => {
this.getBirims();

}, 1000);
}
FORM_MODEL.push(new DynamicSelectModel({
id: element.propertyName,
label: element.displayName,
placeholder: element.displayName,
options: this.dynamicSelectModelBirims, // or this.getBirims();

//value: "Aktif",
//disabled: false,

}))

getBirims() {
this.birimlerService.get().subscribe(
(data: any) => {
if (data.statusCode == 200) {
this.birimler = data;

this.birimler.data.forEach(element => {
this.dynamicSelectModelBirims.push({
label: element.birimAdi,
value: element.id
});
});
}
}
);

The dynamic form in which I have provided code examples above must be loaded with dropdown data before loading html page. But because of the html page was previously installed, the page is loading with an empty dropdown before the service set datas to object. So the dropdown is empty. But when I print with console.log, the dynamicSelectModelBirims object has data. How can I solve this asynchronous problem ?

Mustafa Erdoğmuş 6 days ago
  • Whitelisted Links