How can I create a static option that links to another page using ng-options?
<select class="form-control"
ng-model="person"
ng-options="person.name for person in persons">
</select>
I am trying to use the select element with ng-options and a predefined list of persons, where each person is an object. I attempted to use ng-repeat instead, but it was unsuccessful:
<select ng-model="person" onChange="window.location.href=this.value">
<option value="#/home">Anywhere</option>
<option value="#/current" ng-repeat="person in persons">{{person.name}}</option>
</select>
The variable $scope.person holds the value "#/current". In this case, the linking works, but ng-model fails. The variable $scope.person should represent the selected person.
I expect that $scope.person will have the selected value, unless the user chooses "Anywhere", in which case they should be redirected to another page.
"#/home" and "#/current" represent different URL locations. "#/home" is the home page and "#/current" is the current page. The onChange event redirects the user to the home page or reloads the current page.
Therefore, when the user selects "Anywhere," they should be redirected to the home page. For any other option, the user's page should remain unchanged.