У меня есть выпадающее меню, и я хочу использовать директиву angular2 для обработки открывания/закрытия этого выпадающего списка. Как добавить класс open
в раздел latest-notification
. зная, что моя директива применяется к тегу button
!Добавить класс в следующий элемент в Angular2 Директива
Вот мой HTML-код:
<div class="header-notification" (clickOutside)="showPopupNotification = false">
<button appDropdown>
<span [class.has-notification]="hasNotification"></span><icon name="ico_notification"></icon>
</button>
<div class="latest-notification">
<span class="top-pointer"><icon name="arrow-popup"></icon></span>
<div class="wrap">
<ul>
<li *ngFor="let notify of notifications" [class.seen]="notify.seen">
<a>
<avatar src="{{notify.userProfileUrl}}" size="35"></avatar>
<time>{{notify.createAt}}</time>
<h5>{{notify.name}}</h5>
<p>{{notify.message}}</p>
</a>
</li>
</ul>
</div>
</div>
</div>
А вот моя директива:
import {Directive, HostBinding, HostListener} from '@angular/core';
@Directive({
selector: '[appDropdown]'
})
export class DropdownDirective {
private isOpen = false;
@HostBinding('class.open') get opened() {
return this.isOpen;
}
@HostListener('click') open() {
this.isOpen = !this.isOpen;
}
constructor() { }
}
@micronyks Конечно. Как я могу это достичь? – Sajad
Итак, вы готовы? – micronyks
@micronyks нет ждать, позвольте мне разогреться !!! – Sajad