选择ng-repeat

时间:2015-11-17 11:57:43

标签: angularjs

$scope.vehicles = [ {
			id : 'vehicle1'
		} ];
$scope.addNewVehicle = function() {
			var newItemNo = $scope.vehicles.length + 1;
			// var n = $scope.vehicles.length -1;
			$scope.vehicles.push({
				'id' : 'vehicle' + newItemNo
			});
 $scope.getdetail = function(vin, index) { 
$scope['typeOptions' + index] = d.data.vehicleVINDetailsFeed.trims; 
$scope.trim[vehicle.id] = $scope['typeOptions' + index][0];
   }
<div class="col-lg-6  text-right">
						<a ng-click="addNewVehicle()" class="btn btn-link"
							id="add-newvehicle" style="color:#0000ff; cursor:pointer">add new</a>
					</div>
<div class="col-lg-12 form-content vin-inner"
						ng-repeat="vehicle in vehicles">
  <input type="text" class="form-control"
										ng-class="{redBorder: (registrationForm.$submitted && !registrationForm.vin{{$index}}.$valid)}"
										ng-model="vin[vehicle.id]" name="vin{{$index}}" placeholder="VIN" required
										maxlength="17">
									<button type="button" class="btn btn-info"
										id="registration-preview" ng-click="getdetail(vin[vehicle.id], $index)">
										review
									</button>
<select class="trim-select" ng-model="trim[vehicle.id]"
									name="trim{{$index}}" id="trim{{$index}}"
									ng-options='option as option for option in typeOptions{{$index}}'
									ng-change="changeDetails($index, trim[vehicle.id])">
								</select>
  </div

如果我点击添加“添加新”链接vin输入框,查看按钮和选择框将重复,它按预期工作。如果您在vin字段中输入vin编号并单击查看,则selcet下拉列表将从restAPI响应中加载日期,该部分也正常工作。我的问题是我要选择第一个选项将默认选中。因此,即使您添加更多vin输入会话,并单击相应vin输入的预览,选择选项也应加载相应的响应,第一个选项应选择默认值。我不能在plunker中创建它,因为有很多服务器依赖

我希望我转达我的问题。谢谢你的帮助

0 个答案:

没有答案