Reset dropdown to empty option after selecting some values

14,561 views
Skip to first unread message

Dmitry

unread,
Aug 28, 2012, 5:49:21 AM8/28/12
to ang...@googlegroups.com
Hi
I'm trying to reset dropdown to the empty option, like  "--Select something --"

<select ng-model="selectedCreteria" ng-change="saveField('filters')">
    <option selected="selected" value="">Select creteria</option>
    <option ng-repeat="item in DCA_items" value="{{item.value}}">{{item.label}}</option>
</select>

it works when I first time doing this, but not after.

This is really common task, and I can'r believe that this is impossible.

I've created small jsFiddle for this: http://jsfiddle.net/dmitrysh/8LcwJ/

Could someone give me an advice?

Thank you in advance.

Dmitry

unread,
Aug 29, 2012, 8:10:42 AM8/29/12
to ang...@googlegroups.com

So the only way to do this, is to add empty option as an item to ngRepeat,
and then set it inside controller. Looks strange for me, and why simple solution like
        $scope.selectedCriteria = '';

works, but only for  the first select ? 
default: no value ->  select something ->reset works -> select something again -> reset doesn't works

Getulio Romão Campos Junior

unread,
Aug 29, 2012, 8:50:40 AM8/29/12
to ang...@googlegroups.com
Take a look at ngOptions, instead of setting value and using ngrepeat for the Select control




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages