2017-04-13 39 views
0

我正在看ng2-bootstrap庫中的bs-popover: http://valor-software.com/ngx-bootstrap/#/popover。但是我沒有看到任何關於如何從組件代碼中打開/關閉popover的例子。有沒有人做過這個?這是我目前的視圖模板:ng2-bootstrap從組件打開彈出窗口?

<template #tipTemplate> 
    <div class="row pop-container" style="position: relative; overflow: hidden;"> 
     <div class="row"> 
      <div class="col-sm-12"> 
       <button (click)="pop.hide()" class="btn btn-sm btn-danger pull-right"> 
        <span class="glyphicon glyphicon-remove-circle"></span>&nbsp;Close 
       </button> 
      </div> 
      <div class="row"> 
       <div class="col-sm-12"> 
        <line-chart></line-chart> 
       </div> 
      </div> 
     </div> 
    </div> 
</template> 

<div class="row"> 
    <div class="col-sm-1 col-sm-offset-1"> 
     <button type="button" class="btn btn-xs btn-primary" (click)="pop.show()" container="body"> 
      <i class="fa fa-line-chart" aria-hidden="true"></i> 
     </button> 
    </div> 
    <div class="col-sm-10"> 
     <span [popover]="tipTemplate" 
       #pop="bs-popover" 
       popoverTitle="Labs" 
       placement="bottom" 
       triggers="" 
       class="lab-title"> 
      Troponin 
     </span> 
    </div> 
</div> 

而且它的正常工作,但不是我的按鈕的單擊事件的直接打開酥料餅的,我想在我的組件,然後做了幾件事情和一個調用的函數他們是開放的popover。這個庫可以這樣嗎?

回答

1

您需要添加這個您component.ts

import { Component, OnInit, ViewChild } from '@angular/core'; 

組件內內,

@ViewChild('childModal') public childModal: ModalDirective; 

,然後,當你想打開的模態

this.childModal.show(); 
+0

井上面的代碼是爲模態,但你可以使用相同的 – Sajeetharan

+0

謝謝!我應該已經意識到,相同的模式將窩rk爲popover :)。 – cobolstinks