2016-09-05 2 views
0

Okay, so dass ich ein Dropdown mit Werten aus einem Dienst bevölkern:Set zwei "lokale" Optionen in einer ngSelect

<select ng-model="things.thing" id="thing" name="thing" 
     ng-options="thing.id as thing.description for thing in things" > 
    <option value="" selected>Select a thing</option> 
</select> 

Mit dem json:

[ 
    {"id": 1, "description": "this is an option"}, 
    {"id": 2, "description": "second option right here"}, 
    {"id": 3, "description": "there are three even"}, 
    etc 
] 

Das gibt das folgende:

html page

Aber mein Ziel ist es, eine zusätzliche Option "unbekannt Ding", dass af haben Wenn ausgewählt wird, wird ein anderes Eingabefeld mit einer ng-show aktiviert, wo der Benutzer sein eigenes Ding angeben kann. Aber wenn ich ein extra <option> hinzufügen wird dies in der Ausgabe ignoriert?

<option value="0">Add new thing</option> 

Dies ist die Ausgabe: Snapshot from Firefox Inspector

keine zusätzliche Option. Kann ich das nicht tun? Wie würde ich das zur Arbeit bringen?

Antwort

0

Sie können versuchen, Optionen anstelle von ng-Repeat in ausgewählten

<select ng-model="selectedThing" > 
    <option value="Select a thing">Select a thing</option> 
    <option ng-repeat="($thing_index, thing) in things track by $thing_index" ng-value="thing.description">{{thing.description}}</option> 
</select> 

In Controller wiederholen:

$scope.selectedThing = 'Select a thing' 
    $scope.things = [ 
     {"id": 1, "description": "this is an option"}, 
     {"id": 2, "description": "second option right here"}, 
     {"id": 3, "description": "there are three even"} 
    ] 
+0

Das funktioniert! Event, obwohl diese