|建议您在选择菜单中添加一个ng模型属性,例如
ng-model="selectedValue"
这将保留所选的值,并且您可以使用
$scope.selectedValue
您还应该添加一个
ng-change
属性设置为“选择”菜单,以便在选择某个选项时调用函数。
HTML选择菜单代码:
<select class="mdb-select md-form" ng-model="selectedValue" ng-change="selectSource()" aria-labelledby="dropdownMenuButton" id="sourcesByName">
<option class="dropdown-item" ng-repeat="source in showsource">{{source}} </option>
</select>
在主控制器中
var Report = angular.module('Report', []);
Report.controller('mainController', function($scope, $http) {
$scope.showdata = {};
$scope.selectSource = function(){
//This function will be called whenever a new option is selected.
//log the selectedValue to check it
console.log($scope.selectedValue);
//perform http request here with the selectedValue in order to retrieve
//the corresponding data from the database.
//Once the data is retrieved, we update the $scope.showdata variable. The view will be automatically updated.
};
});