tommueller / ng-mat-search-bar

An Angular 2+ component for an expandable search-icon.
MIT License
37 stars 9 forks source link

How to access Public methods and properties #34

Closed sam3365 closed 4 years ago

sam3365 commented 4 years ago

Can you provide coding examples how to:

1) Subscribe to the different events (onBlur, onClose, onEnter, onFocus, onOpen) 2) Access the open() and close() public methods from within component typescript code 3) Accessing the searchVisible property.

Thank you.

tommueller commented 4 years ago

Hi @steve1mercury This is really basic Angular functionality, so I will not get into details. Some hints:

  1. the events can be subscribed to from template, i.e.:
    <mat-search-bar (onBlur)="yourOnBlurFunction($event)"></mat-search-bar>
  2. you will need to get the component instance in the ts code. Usually this will be done using the @ViewChild-decorator:
    
    @ViewChild(MatSearchBar) matSearchBar;

...

yourFunction() { if (this.matSearchBar.searchVisible) doSomething(); else this.matSearchBar.open(); }



Hope this helps!