无法在文本框中获取所选名称的值

时间:2017-10-23 10:17:08

标签: angularjs

我从服务器获得响应并将其存储到tax变量中我的代码我在第一个下拉列表中获取税名,我还想在下一个文本框中显示相应的值,但它不起作用。



   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>
&#13;
&#13;
&#13;

如何在文本框中获取所选名称的值。

1 个答案:

答案 0 :(得分:1)

在ng选项中,将整个对象分配给<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>
.exchange