1

Angular newbie question

I have a dropdown showing days from week something like this

<select class="form-control" id="selectedDayofWeek" ng-model="selectedDayofWeek" ng-selected="sdw">
                          <option value="">Select</option>
                          <option value="Monday">Monday</option>
                          <option value="Tuesday">Tuesday</option>
                          <option value="Wednesday">Wednesday</option>
                          <option value="Thursday">Thursday</option>
                          <option value="Friday">Friday</option>
                          <option value="Saturday">Saturday</option>
                          <option value="Sunday">Sunday</option>
                        </select>

In my controller I have

$scope.sdw = json[0].DayofWeek; // Thursday

However this does not selects the dropdown's Thursday value

1 Answer 1

2

You want the ng-model specified in your HTML to be of the same name on your $scope.

Change $scope.sdw = json[0].DayofMonth into

$scope.selectedDayofWeek = json[0].DayofMonth;

The ng-selected is redundant (and not used well, read about it here).

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

2 Comments

I initially tried this (i mean $scope.selectedDayofWeek = json[0].DayofWeek) but it didnt work. So then I googled and found ng-selected thing but that didnt work either. Thanks for your comment. Any other thoughts?
Are you sure that json[0].DayofWeek contains Thursday exactly? it is case sensitive. Anyway, see this fiddle for a simple example: jsfiddle.net/bjamqfru/1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.