简体   繁体   中英

AngularJS how can select value from ng-options

i am inserting value in select ng-options and i want to select in dropdown for particular month. this is return all 12 month arrray, so how can i fetch only selected month from dropdown.

Script:

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

要设置所选的第一项,请使用$scope.selectmonth = $scope.Month[0] ,通过设置$scope.selectmonth = $scope.Month将整个数组设置为模型

use this code: see plunker

controller:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM