3

How would/can you populate a ng-admin "choice" field using angular $http.get method call?

2 Answers2

2

Something like this would pull a list of companies from the '/companies' endpoint and populate the select field with it. It will also highlight the currently selected company. It won't be a "choice" kind of field.

      nga.field('company.id', 'reference')
      .label('Company')
      .targetEntity(admin.getEntity('companies'))
      .targetField(nga.field('name'))
      .validation({required: true }),

You can try creating a custom directive, but you'll have to dig through the ng-admin internals to make sure you work with their API. And then you'll have to pray they don't change that api. Custom directives are easier to think about and manage if you're saving one field at a time and not filling out a huge form. But if you're saving one field at a time, you'll operating outside of ng-admin and if you do enough of those tricks, then you won't need ng-admin other than for basic listings and pagination.

Andrei R
  • 4,904
  • 5
  • 25
  • 26
1

You're probably looking for the 'reference' field (see documentation). If this doesn't fit your need, you'll have to use a custom directive using ui-select (already used by ng-admin) and a custom Restangular call.

Pointers:

François Zaninotto
  • 7,068
  • 2
  • 35
  • 56