javascript - how to get sub value in array for ng-repeat option on angulars js? -


use ng-repeat can't option value!

plz help! html:

<ul ng-controller="app">     <li ng-repeat="mainlist in mainlists">     <p>{{mainlist.name}}</p>     <select ng-options="mainlist.list mainlist.list in mainlists.list">       <option value="">{{mainlist.list.name}}</option>     </select>   </li> </ul> 

this demo

js: {{mainlists.name}} not {{mainlists.list.name}}

function app($scope) {     $scope.mainlists = [     {       "name":"main001",       "list":[         {           "no":"1",           "name":"sub1"         },{           "no":"2",           "name":"sub2"         }]      },    {       "name":"main002",       "list":[         {           "no":"2-1",           "name":"sub1"         },{           "no":"2-2",           "name":"sub2"         }]      }]  }; 

this demo

ngoptions directive requires ngmodel directive defined on select element.

this not documented pitfall, visible source code

so, selects work if add ngmodel them:

<select    ng-model="mainlist.value"    ng-options="item item.name item in mainlists.list" > </select> 

or, if not planning wire selects model (very unusual case), might want use ng-repeat select options:

<select>   <option ng-repeat="item in mainlist.list">{{item.name}}</option> </select> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -