Scenario:
When the user clicks the link, a dropdown is shown and clicks other than the link, the dropdown list is hidden. I have done the showing part, but don't know where to start for hiding the dropdown.
Code:
login.component.html
<div class="actions login__block__actions">
<div class="dropdown" [ngClass]="{'open':showOption}">
<a href="#" data-toggle="dropdown" (click)="toggleOption($event)"><i class="zmdi zmdi-more-vert"></i></a>
<ul class="dropdown-menu pull-right">
<li><a data-block="#l-register" href="">Create an account</a></li>
<li><a data-block="#l-forget-password" href="">Forgot password?</a></li>
</ul>
</div>
</div>
login.component.ts
@HostListener('document:click', ['$event'])
toggleOption(event) {
console.log(this._eref.nativeElement.contains(event.target));
if (this._eref.nativeElement.contains(event.target)) {
this.showOption = !this.showOption;
} else {
this.showOption = false;
}
}
Screen:
Any advice would be helpful. Thanks.
