javascript - Initializing select value in nested ng-repeat -
i'm having trouble initializing select boxes in form, built nested ng-repeats. have parent table rows built ng-repeat, , select box value bound attribute in parent row. values in select box pulled nested child array, constituting available selections row.
<tr ng-repeat="asv in asvs"> <td>{{asv.scenario_asv_id}}</td> <td>{{asv.asv_target_id}}</td> <td><select ng-model="asv.asv_target_id"> <option ng-repeat="version in asv.asv_targets" value="{{version.asv_target_id}}" ng-selected="asv.asv_target_id == version.asv_target_id"> id: {{version.asv_target_id}} - name: {{version.asv_target_desc}} </option> </select> </td> </tr> in plunker, you'll see first 2 selects initialize properly, yet 3rd not. can advise how implement properly?
it recommended use ng-options select elements. please replace select code example below:
<select convert-to-number ng-options="version.asv_target_id ('id: ' + version.asv_target_id + ' - name: ' + version.asv_target_desc) version in asv.asv_targets track version.asv_target_id" ng-model="asv.asv_target_id"> </select> because value numeric have add following directive per https://code.angularjs.org/1.4.7/docs/api/ng/directive/select
module.directive('converttonumber', function() { return { require: 'ngmodel', link: function(scope, element, attrs, ngmodel) { ngmodel.$parsers.push(function(val) { return val != null ? parseint(val, 10) : null; }); ngmodel.$formatters.push(function(val) { return val != null ? '' + val : null; }); } }; });
Comments
Post a Comment