app.module.ts私は隠したいAngular2 NG2-ポップオーバーの非表示は、()
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例外:プロパティを読み取ることができません '隠す' 未定義
のPopoverContent.hide(PopoverContent.jsで:78 )
'PopoverContent.js'ファイルにはthis.popover.hide();という行があります。しかし私はそれをどのように初期化するか分かりません。私の理解として@ViewChildは#customPopover、すなわち私の場合popover-contentにクラスバインドを初期化するだけです。誰かが私に 'Popover'を初期化するための解決策を教えてもらえますか?
おかげ@Sanket手がかりを与えます。はい 'this.customPopover'は未定義です。私は以下のコードを使用して解決しました。 –