Amit Agarwal
Amit Agarwal

Reputation: 61

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>

Upvotes: 0

Views: 64

Answers (2)

Mukund Kumar
Mukund Kumar

Reputation: 23221

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>

Upvotes: 0

Narek Mamikonyan
Narek Mamikonyan

Reputation: 4611

For setting first item selected use $scope.selectmonth = $scope.Month[0], by setting $scope.selectmonth = $scope.Month U setting whole array as a model

Upvotes: 0

Related Questions