AngularJS Select the item that sets the selected index

So, I am using angular, and this is my select html:

<select id="date" ng-model="selectedDay" ng-change="setDate()" > <option>another option</option> <option>an option</option> </select> 

this is in my controller:

 $scope.selectedDay; document.getElementById("date").selectedIndex = "0"; 

Result: Three options: one empty (which is selected by default), and then two parameters that I made in html

What the hell? why is not the default when I open the view "another option"

+5
source share
1 answer

First, always check the official documentation. AngularJs is well documented.

Secondly, do not use document.getElementById ("date") selectedIndex = "0" - this javascript. Avoid using pure Javascript when the Angular function is available.

Documentation:

https://docs.angularjs.org/api/ng/directive/select

https://docs.angularjs.org/api/ng/directive/ngSelected

+6
source

Source: https://habr.com/ru/post/1204104/


All Articles