I've referred to this other walk through and am not able to understand exactly how it works. I've added this into my ts file:
@Component({
host: {
'(document:click)': 'onOutsideClick($event)',
},
})
class SomeComponent() {
constructor(private _eref: ElementRef) { }
onOutsideClick(event) {
console.log('click')
if(!this._eref.nativeElement.contains(event.target)){
this.companyResults = null;
}
}
And want to apply it to this dropdown in HTML where someone will have the ul data set to null when clicked outside.
<input id="positionCompanyName" name="companyName_{{i}}" class="search-input"
[(ngModel)]="candidate.positions[i].company_name"
(keyup)="$event.target.value && searchCompany$.next($event.target.value)">
<ul class="search-dropdown-ul" *ngIf="companyResults && positionIndex === i">
<a class="search-dropdown-div" *ngFor="let companyResult of companyResults" (click)="addCompany(companyResult, i)">
<li class="search-dropdown-li">
{{ companyResult.name }
</li>
</a>
</ul>