我必须通过输入表单将参数发送到API链接。
这是我的选择
<select ng-model="selectedDay" ng-change="changedValue(selectedDay)" style="width: 117px;">
<option ng-repeat="x in filterDays" value="{{x.showDays}}">{{x.showDays}}</option>
</select>
这是我的控制器
$scope.filterDays = [
{ showDays: "Last month", value: 30 },
{ showDays: "Last 14 days", value: 14 },
{ showDays: "Last 7 days", value: 7 }
];
$scope.show = $scope.filterDays[0].value;
$scope.changedValue = function (selectedDay) {
$scope.show = selectedDay;
}
$http.get("http://localhost:8080/api/overviewStatisticTeam?days=" + $scope.show)
当我在select上更改值时,我遇到了向API发送参数的问题。谢谢你的帮助
答案 0 :(得分:2)
您必须将值绑定到value属性而不是showDays。像这样更改代码:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.filterDays = [
{ showDays: "Last month", value: 30 },
{ showDays: "Last 14 days", value: 14 },
{ showDays: "Last 7 days", value: 7 }
];
$scope.show = $scope.filterDays[0].value;
$scope.changedValue = function (selectedDay) {
console.log(selectedDay)
$scope.show = selectedDay;
}
});
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedDay" ng-change="changedValue(selectedDay)" style="width: 117px;">
<option ng-repeat="x in filterDays" value="{{x.value}}">{{x.showDays}}</option>
</select>
</div>
</body>
</html>
&#13;