我正在使用Spring + AngularJS。如何在angularjs中发送后端下拉值?
HTML:
<div class="col-md-4">
<select ng-model="algoList">
<option ng-repeat="algo in algoList" value="{{algo}}">{{algo}}</option>
</select>
<button class="btn btn-primary" ng-click="applyAlgo()">
<span class="glyphicon glyphicon-right"></span> Apply
</button>
</div>
JS:
$scope.algoName = "";
$scope.algoList= ["DC_CleaningOperations","FilerOperation"];
$scope.applyAlgo = function() {
var response = $http.post('/idw-dv/getAlgo', $scope.algoName);
response.success(function(data, status, headers, config) {
swal("Following algorithm is applied successfully. :",data,"success");
console.log(data);
});
response.error(function(data, status, headers, config) {
swal( "Exception details: " + JSON.stringify({data: data}));
});
控制器:
@RequestMapping(value = "/getAlgo", method = RequestMethod.POST)
@ResponseBody
public String getAlgorithm(@RequestBody String algoName) {
return algoName;
}
答案 0 :(得分:0)
所以这就是问题,你为select字段定义的模型是错误的,最终会引发你的问题。
如果您将ng-model更改为“algoName”,则下拉列表中的所选值现在将存储在algoName中。
此值现在将作为String传输到Spring Controller。
希望这有效......
<div class="col-md-4">
<select ng-model="algoName">
<option ng-repeat="algo in algoList" value="{{algo}}">{{algo}}</option>
</select>
<button class="btn btn-primary" ng-click="applyAlgo()">
<span class="glyphicon glyphicon-right"></span> Apply
</button>
</div>