1

I have to send the parameter through the input form to the API link.

This is my selecct

<select ng-model="selectedDay" ng-change="changedValue(selectedDay)" style="width: 117px;">
    <option ng-repeat="x in filterDays" value="{{x.showDays}}">{{x.showDays}}</option>
 </select>

And this is my controller

$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)

I have problem with sending paramter to API, when I change value on my select. Thanks for help

0

1 Answer 1

2

You have to bind value to your value attribute instead of showDays. Change the code like this:

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;
}
});
<!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>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.