javascript - Angular JS dynamically populate options for Select fields -


i have problem can't figure out in angular (i new angular not js).

essentially have html template gets repeated loops through array of results returned post request. works fine, except have select field repeated each time loop goes round.

the template shows adverts, , each advert has date created. trying achieve , have done js , ejs before below:

            var today = moment();             var ad_date = moment(ad.ad_date);             var diff = today.diff(ad_date,'days');             var lowend = 1;             var highend = 14 - diff;             var arr = [];             while (lowend <= highend) {                 arr.push(lowend++);             } 

and in ejs had

             <select class="form-control" name="offer_time">                 <% (var d in arr) { %>                     <option value="<%= arr[d] %>"><%= arr[d] %></option>                 <% } %>             </select> 

my question how can same thing in angular?

i thinking (although wrong) have function in controller returns array above , ng-repeat maybe inside select?

any ideas or thoughts appreciated!

thanks

you find need in ng-option documentation

the code :

<select ng-options="item.subitem item.label item in values "ng-model="selected"></select> 

in ng-options, have list (item here). item.label show in list meanwhile item.subitem save in ng-model.

in exemple seems have simple value, not object. should give :

<select class="form-control" name="offer_time" ng-options="item item in items" ng-model="selected"></select> 

items list, , item see , save. don't need part as


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -