Here I am using prime ng dynamic form. 
<http://ng2-dynamic-forms.udos86.de/sample/index.aot.html#/primeng-sample-form>
Model

 dynamicSelectModelBirims: SelectModel[] = [];

 export class SelectModel {
    label: string;
    value: any;
 }

Constructor

constructor(private formService: DynamicFormService, private helperService: 
HelperService,
    private birimlerService: BirimlerService) {

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

    }, 100);

    setTimeout(() => {
      this.getBirims();

    }, 1000);

  }

new DynamicSelectModel

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

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

    }))

getBirims(){} and DynamicSelectModel push

 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
        });
      });
    }
  }
);

HTML

 <div class="overflow-hidden content-margin content-padding" style="width: 
100%;">
    <!-- <pre>{{ dynamicform | json }}</pre> -->
    <form [formGroup]="formGroupValue" class="ui-fluid" style="align-content: 
center">

        <dynamic-primeng-form [group]="formGroupValue" [layout]="layoutJson" 
[model]="formModel"
            (change)="onChange($event)" 
(pEvent)="onPEvent($event)"></dynamic-primeng-form>

    </form>

    <!-- <button type="button" class="" icon="pi pi-check"  
label="Kaydet"></button> -->

</div>

empty dropdown image <https://i.stack.imgur.com/OwSgB.jpg>

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 ?

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to