set selected value in angular5 ng-select programmaticaly

后端 未结 1 1299
清歌不尽
清歌不尽 2021-01-25 06:35

I\'m using angular5 ng-select component: https://github.com/ng-select/ng-select and try to set the selected value (programatically) when the container component

相关标签:
1条回答
  • 2021-01-25 07:01

    Just find the item

        let item = this.ngSelect.itemsList.findByLabel('label of the item');
    

    and then set it back

        this.ngSelect.select(item);
    

    you need a reference to ng-select in your angular component

        @ViewChild(NgSelectComponent)
        ngSelect: NgSelectComponent;
    
    0 讨论(0)
提交回复
热议问题