You can access the dropdown from within the TS file by using @ViewChild().
Add a template variable to the ngbDropdown for example #dropdown
<div #dropdown ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Toggle dropdown
</button>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<button ngbDropdownItem>Action - 1</button>
<button ngbDropdownItem>Another Action</button>
<button ngbDropdownItem>Something else is here</button>
</div>
</div>
Then use @ViewChild() in your typescript file. You can then call the open method on the dropdown from within the typescript
@Component({
selector: 'ngbd-dropdown-basic',
templateUrl: './dropdown-basic.html',
})
export class NgbdDropdownBasic {
@ViewChild(NgbDropdown, { static: true })
public dropdown: NgbDropdown;
public toggleDropdown(): void {
this.dropdown.open();
}
}
A working Stackblitz example...
https://stackblitz.com/edit/angular-7vbmva