kelp404 / angular-form-builder

Drag and drop to build bootstrap forms in AngularJS.
http://kelp404.github.io/angular-form-builder/
MIT License
600 stars 340 forks source link

Registercomponent with Json Data #70

Open samemickey opened 9 years ago

samemickey commented 9 years ago

Hi, I am creating a dependent dropdown component for which I am using data from a json. I have tried 2 options till now:

  1. Call json and register the component once the data is received. This creates the component not until an click action anywhere on the form is done (view is refreshed).

    $.getJSON('/assets/json/data.json').then(function(data) { $builderProvider.registerComponent('dependentDrop', { options: data.data, .... }); });

  2. call json separately and store the data in an array and use this data in the component. but the component gets registered before the data is saved in the array thus populating empty dropdown.

    var dependentOptions =[];
     $.getJSON('/assets/json/data.json').then(function(data) {
         dependentOptions = data;
     }); 
    
     $builderProvider.registerComponent('dependentDrop', {
      options: dependentOptions ,
       ....
      }

Please suggest, how to get the data populated in the drop down with json data.

thanks, mickey