0

I have a dropdown list and I'm using AngularJS as the frontend framework. However the first value in dropdownlist is always empty. Can anyone explain to me what happened? where I need to change? Thanks!

here is the html

 <div class="input-control select" ng-controller="democtrl">
            <select ng-model="selectedOption">
                <option selected>Select the option</option>
                <option value="ip">IP</option>
                <option value="host">Host</option>
            </select>
            {{selectedOption}}
        </div>

here is the js code:

 angular.module('demo')
      .controller('democtrl', ['$scope', function ($scope) {
            $scope.selectedOption = "test";

      }]);
1
  • your angular module definition does not have dependencies defined. Try changing it to angular.module('demo',[]). You can find the plunk here embed.plnkr.co/9SdR02Hro7ORz7zf20Ea Commented Mar 27, 2016 at 3:39

1 Answer 1

4

That's because you don't have any html option with value test but you are setting the model to this value.

Try either leaving selectedOption empty or setting it to the an existing value:

angular.module('demo')
      .controller('democtrl', ['$scope', function ($scope) {
            $scope.selectedOption = "ip";
      }]);

Hope this helps!

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

2 Comments

Thanks a lot! This does help! It saves my time! ;-)
@catlovespurple Glad it does. Please mark as correct answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.