Clear selected option in ui-select angular

前端 未结 4 544
一生所求
一生所求 2020-12-24 05:01

Anyone know how to clear the selected value of an ui-select box in angular?

I want the functionality of select2 where you have a small x in the selectbox. Doesn\'t l

4条回答
  •  爱一瞬间的悲伤
    2020-12-24 05:35

    You could add a small X button when you display the selection.

    
      {{$select.selected.name}}
      
    
    

    Then you stop the click event from bubbling up and trigger the open event. And you clear the field by overwriting the selected model.

    $scope.clear = function($event) {
       $event.stopPropagation(); 
       $scope.country.selected = undefined;
    };
    

    Here's the plnkr. http://plnkr.co/edit/qY7MbR

提交回复
热议问题