I had a strange problem when setting the value of the drop-down list model in the document ready event. I want Option4 to be selected when the page loads, however this does not seem to be reflected in my view when I do the following. Please see below code ...
HTML
<select ng-model="search_for" class="form-control" id="search_for">
<option value="">-Search For-</option>
<option value="1">Option1</option>
<option value="2">Option2</option>
<option value="3">Option3</option>
<option value="4">Option4</option>
</select>
Js
angular.element(document).ready(function () {
$scope.search_for = 1;
}
Even when I do {{search_for}} in html, it proves that the model value is not set, showing nothing, but shows the value when the value of the drop-down list changes.
What am I doing wrong?
Thank.
source
share