Close menu when using ng-select in angular
Hi,
You can use the close method provided by the NgSelectComponent.
Use @ViewChild to get a reference to the NgSelectComponent in your component:
@Component({
selector: "app-your-component",
templateUrl: "./your-component.component.html",
styleUrls: ["./your-component.component.css"]
})
export class YourComponent {
@ViewChild(NgSelectComponent) ngSelect: NgSelectComponent;
// ... your other component code
}
Now, you can use the close method to close the menu:
typescript
Copy code
closeMenu() {
this.ngSelect.close();
}
<ng-select #mySelect>
<!-- your ng-select options here -->
</ng-select>
<button (click)="closeMenu()">Close Menu</button>