在ng-repeat中获取ng-model的值

时间:2016-05-19 05:32:00

标签: javascript angularjs

在我的Angularjs项目中,我在ng-model内使用ng-repeat时遇到问题。当我在选择框中选择值时,选择框会自动选择前一个选定值。我认为这是由于ng-model内的ng-repeat <div ng-repeat="x in data"> <select class="selectbox_menulist" ng-change="endpoint.showEndPointStatsData()" ng-model="graphSelect.value"> <option ng-repeat="opt in mapOptions" value="{{opt.value}}">{{opt.type}}</option> </select> </div> 。我们如何解决这个问题呢?

HTML:

$scope.mapOptions = [
    { value: "bytes",type:"Bytes/sec" },
    { value: "packets",type:"Packets/sec"},
    { value: "megabytes",type:"Megabytes/sec"}
];

 showEndPointStatsData: function() {
        console.log('Function called ====');
        console.log($scope.graphSelect.value);

JS:

List<String> newList = list.stream()
                           .map(x -> x.stream().collect(Collectors.joining(",")))
                           .collect(Collectors.toList());

newList.forEach(System.out::println);

}

2 个答案:

答案 0 :(得分:1)

使用arrayng-model中存储mutli ng-repeat的值:

<div ng-repeat="x in data track by $index">
<select class="selectbox_menulist"  ng-change="endpoint.showEndPointStatsData($index)" ng-model="graphSelect[$index]">
    <option ng-repeat="opt in mapOptions" value="{{opt.value}}">{{opt.type}}</option>
</select>
</div>
  $scope.mapOptions = [{ value: "bytes",type:"Bytes/sec" }, { value: "packets",type:"Packets/sec"},{ value: "megabytes",type:"Megabytes/sec"}];
$scope.graphSelect = new Array($scope.data.length);

showEndPointStatsData: function(index) {
    console.log('Function called ====');
    console.log($scope.graphSelect[index]);

答案 1 :(得分:0)

ng-model inside ng-repeat

jsfiddle

以上链接对如何使用示例

进行了很好的描述