I have a weird problem when setting the model value of a dropdown on Document ready event. I want Option4 to be selected on page load, However this doesn't seems to be reflected on my view when I do things as follows. 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 model value is not set by showing nothing, but shows the value when dropdown value is changed.
What am I doing wrong ?.
Thank You.
document.readyadd at the starting in the controller, since the controller loads prior to view, the model value gets reflected