Open matAutocomplete with open openPanel() method

前端 未结 3 882
谎友^
谎友^ 2020-12-30 02:41

I\'m working with Angular Material\'s matAutocomplete component, and according to the docs, there is a method which can open/close an autocomplete panel with a openPanel()/c

3条回答
  •  死守一世寂寞
    2020-12-30 03:01

    Please add stopPropagation or defer the openPanel using setTimeout as follows.

    Because at button click end focus changes from input field back to ur button so autocomplete is hiding immediately

    Option 1: Stop Propagatioan

    
    ...
    openAutocomplete(evt) {
      evt.stopPropagation()
      this.autoTrigger.openPanel();
    }
    

    Option 2 - SetTimeout

    openAutocomplete() {
      setTimeout(() => {
        this.autoTrigger.openPanel();
      }, 0)
    }
    

提交回复
热议问题