2014-10-29 70 views
0

我在選擇ng選項中插入值,我想在特定月份的下拉列表中選擇。 這是返回所有12個月arrray,所以我如何才能從下拉菜單中提取僅選定的月份。AngularJS如何從ng選項中選擇值

腳本:

$scope.Month = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 
$scope.selectmonth = $scope.Month; 

$scope.SaveReport = function() { 

    PrintReportRepository.save(
      { 
      SelectMonth: $scope.selectmonth, 
      }, 

HTML

<select class="form-control" ng-model="selectmonth" ng-options ="months as months for months in Month">{{months}}</select> 

回答

0

用於設置選擇使用$scope.selectmonth = $scope.Month[0]第一項,通過設置$scope.selectmonth = $scope.Monthü設置整個陣列作爲模型

0

使用這個代碼:見plunker

控制器:

$scope.Month = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 
$scope.SaveReport = function() { 
    console.log('SelectMonth', $scope.selectmonth); 
} 

HTML:

<select class="form-control" ng-model="selectmonth" ng-options ="months as months for months in Month" ng-change="SaveReport()"></select>