Angularjs populate select options with json

前端 未结 4 1061
暗喜
暗喜 2021-02-09 04:54

I am looking to populate select option with values from a basic json array.

The example I have is a country select. Each country has an id element and a name plus other

4条回答
  •  误落风尘
    2021-02-09 05:34

    The best way to populate a standard select(you can use angular-ui-select too) with objects is to use "ng-options" directive and "ng-repeat" using "track by id" (see AngularJS doc), this works well with ng-model. This is an example of how to use it:

    
    

    I must say that "vm" is in case of "controllerAs" defined in the controller, if you use the $scope directly, you can remove the "vm".

    This is the best way that I found to populate a select field.

提交回复
热议问题