How can I populate a select dropdown list from a JSON feed with AngularJS?

前端 未结 3 1141
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 04:35

I have been looking hard for examples but could not find anything at all. The only thing I know is that I could use the http module to get my data. Here is what I am current

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 05:24

    In my Angular Bootstrap dropdowns I initialize the JSON Array (vm.zoneDropdown) with ng-init (you can also have ng-init inside the directive template) and I pass the Array in a custom src attribute

    
    

    Inside the controller:

    vm.zoneDropdown = [];
    vm.getZoneDropdownSrc = function () {
        vm.zoneDropdown = $customService.getZone();
    }
    

    And inside the customDropdown directive template(note that this is only one part of the bootstrap dropdown):

    
    

提交回复
热议问题