Reputation: 11107
I have a select tag that may or may not have options loaded. Everything is fine when the options are provided, but whenever I want a default option to display only when no other options exist, the default option will not appear. The end result is that I have no options available. If you remove the two items in the countries
variable, then you will see what I mean. What's wrong and how do I fix this?
MY FIDDLE
var app=angular.module('App', []);
function ctrl($scope){
$scope.countries = [
{name: 'United States'},
{name: 'Canada'}
]
}
<div ng-app="App" >
<div ng-controller="ctrl">
<select multiple="" ng-multiple="true" ng-model="country_selected"
data-ng-options="country.name for country in countries">
<option value="" ng-hide="countries.length == 0">No countries found</option>
</select>
</div>
</div>
Upvotes: 0
Views: 158
Reputation: 2866
There are two ways:
Use two selects to switch
see an example
Write a custom directive
Upvotes: 1