私はドロップダウンメニューを持っていますが、このドロップダウンのオープン/クローズの処理にangular2ディレクティブを使用したいと思います。 クラスをlatest-notification
divに追加するにはどうすればよいですか。私の指示が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