ng-bootstrap example calling method from component

d-man picture d-man · Sep 20, 2016 · Viewed 9.5k times · Source

angular2 ng-bootstrap drop down dropdown component

Can some one help me to find out how can i bind angular2 component with dropdown and call open or close method..

they don't have much documentation.

Answer

Mateusz Witkowski picture Mateusz Witkowski · Sep 20, 2016

You can use ViewChild decorator. In parent component it should look something like that:

import 'ViewChild' from '@angular/core'
import 'NgbDropdown' from '...';

[...]

export class ParentComponent {
  @ViewChild(NgbDropdown)
  private dropdown: NgbDropdown;

  closeDropdown() {
    this.dropdown.close();
  }
}

You can read more about ViewChild in official documentation: Component Interaction | ViewChild.