2017-10-23 6 views
0

私はサーバーからの応答を取得しており、それを税金変数iのコードに保存しています。最初のドロップダウンリストに税の名前が表示されています。ボックスが動作していません。テキストボックスで選択された名前の値を取得する方法テキストボックスに選択された名前の値を取得できません

var app = angular.module('myApp', []); 
 
    app.controller('addProductController', function ($scope, $http) { 
 
    
 
    $scope.taxes =[ 
 
{id: 43, name: "a", value: 2} 
 
{id: 44, name: "c", value: 1} 
 
]; 
 
};
<script 
 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"> 
 
</script> 
 
<div class="container" ng-app="myApp" ng-controller="addProductController" 
 
> 
 
<select name="e[$index].name" ng-model=" e[$index].name" ng-options="e.name 
 
as e.name for e in taxes" class="form-control" ng-required="true"></select> 
 
          <input type="text" name="name" ng-model="taxes. 
 
[$index].value" class="form-control" ng-required="true" ng-value="e.value"> 
 
          <button type="button" class="btn btn-default 
 
btn-sm" ng-click="removeChoice($index)"> 
 
           <span class="glyphicon glyphicon-minus"> 
 
</span> REMOVE 
 
          </button> 
 
          </div>

答えて

1

ngオプションでは、オブジェクト全体をng-modelに割り当ててアクセスします。

<select name="name" ng-model="selected" ng-options="e as e.name for e in taxes" class="form-control" ng-required="true"></select> 
<input type="text" name="name" ng-model="selected.value" class="form-control" ng-required="true" ng-value="e.value"> 

デモ

var app = angular.module('myApp', []); 
 
    app.controller('addProductController', function ($scope, $http) { 
 
    
 
    $scope.taxes =[ 
 
{id: 43, name: "a", value: 2}, 
 
{id: 44, name: "c", value: 1} 
 
]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div class="container" ng-app="myApp" ng-controller="addProductController" > 
 
<select name="name" ng-model="selected" ng-options="e as e.name for e in taxes" class="form-control" ng-required="true"></select> 
 
          <input type="text" name="name" ng-model="selected.value" class="form-control" ng-required="true" ng-value="e.value"> 
 
          <button type="button" class="btn btn-default btn-sm" ng-click="removeChoice($index)"> 
 
           <span class="glyphicon glyphicon-minus"></span> REMOVE 
 
          </button> 
 
          </div>

+0

はい、それは動作しています。 – xrcwrn

+0

nice。これが役に立ったら答えとしてチェックしてください:)。 –

関連する問題