1

I m having a dropdown for which I am using the ng-options to load the values from the model which is populated by the controller. Now I need to have one more option which is <option value='any'>any</option> which should be there as the selected option by default. How to do this in angular way?

<body ng-controller="myController">
  <h1>States in India!</h1>
  <select ng-options="state for state in states" ng-model="selectedState">      </select>
</body>

Plnkr link attached - Plnkr link

3 Answers 3

1

@Pradeep, use

    <select ng-options="state for state in states" ng-model="selectedState">
        <option value="">-- choose state --</option>
    </select>

plunkr link

Sign up to request clarification or add additional context in comments.

Comments

0

You can simply add one more item in array and assing it to $scope.selected. Plunkr.

$scope.selectedState = "Select";
$scope.states=["Select","Karnataka", "Tamilnadu", "Andra-Pradesh", "Rajasthan"]

Comments

0

write option tag inside the select tag like

  <body ng-controller="myController">
    <h1>States in India!</h1>
    <select  ng-options="state as state for state in states" ng-model="selectedState">
         <option value=''>any</option>
    </select>
  </body>


angular.module("myApp", []).

    controller("myController", function($scope){
      $scope.states=["Karnataka", "Tamilnadu", "Andra-Pradesh", "Rajasthan"]  
    })

I have run in plunker its work please try this

1 Comment

<select ng-options="sta.planStatus as sta.planStatus for sta in status" ng-model="plan.planStatus" > <option value="">Select Status</option> </select>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.