1

Template:

<select id="siteOptions" ng-model="siteVal" ng-change="siteChange()">
     <option ng-repeat = "site in sites" ng-selected="{{site == selectedSite}}"   value="site">{{site}}</option>
 </select>

Controller:

$scope.siteChange = function(){
        console.log(" $scope.siteVal--> "+ $scope.siteVal);
}

I could able to populate values in dropdown properly, but when I try to select value in dropdown I could see "$scope.siteVal--> undefined". Even when I select the dropdown value multiple time ng-change is triggering only once.

1
  • Your code is working fine Commented Dec 29, 2016 at 13:43

1 Answer 1

1

Remove .value attribute from your html markup and your code would work fine!

<select id="siteOptions" ng-model="siteVal" ng-change="siteChange()">
     <option ng-repeat = "site in sites" ng-selected="{{site == selectedSite}}">{{site}}</option>
</select>

From the DOCS

Note: ngSelected does not interact with the select and ngModel directives, it only sets the selected attribute on the element. If you are using ngModel on the select, you should not use ngSelected on the options, as ngModel will set the select value and selected option

Here is the plunker which demonstrates the same

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

2 Comments

Thanks Dhaval, after removing value from html I can access the selected option inside ng-model .
your answer is really helpful. Thank U Dhaval.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.