app.module.ts
import { PopoverModule } from 'ng2-popover';
@NgModule({
declarations: [ ...],
imports: [PopoverModule],
providers: []
})
例子.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>
例子.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”的解决方案吗?