ng2-bootstrap从组件打开Popover?

时间:2017-04-13 18:35:07

标签: angular ng2-bootstrap

我在这里查看ng2-bootstrap库中的bs-popover: http://valor-software.com/ngx-bootstrap/#/popover。但我没有看到如何从组件代码中打开/关闭弹出窗口的任何示例。有没有人这样做过?这是我当前的视图模板:

<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我想在我的组件中调用一个函数,然后做一些事情,其中​​一个打开了popover。这个库有可能吗?

1 个答案:

答案 0 :(得分:1)

您需要在component.ts

中添加此内容
import { Component, OnInit, ViewChild } from '@angular/core';

在组件内部,

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

然后,每当你想打开模态

 this.childModal.show();