app.module.tsAngular2 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类型错误:无法读取的不确定
在PopoverContent.hide(PopoverContent.js属性 '隐藏':78 )
在'PopoverContent.js'文件中有this this.popover.hide();但我不知道如何初始化它。正如我的理解是@ViewChild只初始化类绑定到#customPopover,即在我的情况弹出内容。有人可以给我一个解决方案来初始化'Popover'吗?
感谢@Sanket给了一个线索。是'this.customPopover'未定义。我使用下面的代码解决了它。 –