formly-js/angular-formly

A way to preload options in select from http but not using javascript functions directly in JSON

Opened this issue · 1 comments

If I load this field from query to the server (examples: REST, AJAX, HTTP)

    [{
        "key": "countries",
        "type": "select",
        "className": "col-xs-6",
        "templateOptions": {
            "label": "Countries",
            "options": [
                {"name": "UK", "id":1},
                {"name": "France", "id":2},
                {"name": "Japan", "id":3}
            ],
            "valueProp": "id",
            "labelProp": "name",
            "required":true
        }
    }]

This JSON is loaded from server like a txt string and I do not want to use functions in options, only a name of a service predefined inside angular which will load the data (key-value format).

I do not know if it is possible that after resolving the promise of the load in the service the list is reflected in the options of the select.

Do you think it is better to create a new type of customize select?
And within the definition of the new type create a controller where receive the data of the default resource from where load the data.
Even it could be a simple URL wi can fill in templateOptions to make it more general and use in the controller for get the data for the options and refresh the select.

Is there an example of this?

Thanks to all the team for your brilliant work with angular-formly.