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'未定義。我使用下面的代碼解決了它。 –