Clear selected option in ui-select angular

前端 未结 4 570
一生所求
一生所求 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:41

    Note: if we used tagging and tagging-label="false" in that case allow-clear functionality not work.

    Custom clear functionality

    HTML Code

    
     {{$select.selected.description || $select.search}}
     
    
    

    Controller action Code

    function clear($event, $select){ 
     //stops click event bubbling
     $event.stopPropagation(); 
     //to allow empty field, in order to force a selection remove the following line
     $select.selected = undefined;
     //reset search query
     $select.search = undefined;
     //focus and open dropdown
     $select.activate();
    }
    

提交回复
热议问题