app.module.ts
import { PopoverModule } from 'ng2-popover';
@NgModule({
declarations: [ ...],
imports: [PopoverModule],
providers: []
})
example.html
<a [popover]="customPopover" [popoverOnHover]="true" [popoverCloseOnMouseOutside]="true" href="www.google.com" (click)="$event.stopPropagation()" target="_blank">{{name}}</a>
<!--Popover content -->
<popover-content #customPopover title="{{name}}" placement="right"
[closeOnClickOutside]="true" [closeOnMouseOutside]="true">
<span class="popoverDesc">{{description}}</span><br /><br />
<a href="{{websiteLink | formatUrl:'url'}}" (click)="$event.stopPropagation()" target="_blank">{{websiteLink | formatUrl:'text'}}</a><br /><br />
<button class="btn btn-secondary popoverBtn" (click)="toggleAddToListModalPopover($event)">Add to list</button>
</popover-content>
example.component.ts
import { PopoverContent } from 'ng2-popover';
@ViewChild('customPopover') customPopover: PopoverContent;
protected toggleAddToListModalPopover(e):void {
this.customPopover.hide();
this.showAddToListModal = !this.showAddToListModal;
e.stopPropagation();
}
モーダルが開いたときにポップオーバーを非表示にしたい。「customPopover.hide()」関数を呼び出すと、エラーが発生します。
error_handler.js:51 TypeError: undefined のプロパティ 'hide' を読み取れません
PopoverContent.hide (PopoverContent.js:78) で
「PopoverContent.js」ファイルには、行 this.popover.hide(); があります。しかし、私はそれを初期化する方法がわかりません。私の理解では、@ViewChild は #customPopover へのクラス バインドのみを初期化します。つまり、私の場合は popover-content です。「ポップオーバー」を初期化するための解決策を教えてください。