【问题标题】:ngx Bootstrap manual close buttonngx Bootstrap 手动关闭按钮
【发布时间】:2018-02-20 09:55:06
【问题描述】:

我正在尝试使用 ngx-bootstrap 在弹出框的右上角制作一个手动弹出框关闭按钮。我知道要添加 x 按钮,我们必须使用引导程序中的 &Times。

https://v4-alpha.getbootstrap.com/utilities/close-icon/

但是我不知道如何在我的标题中实现它,因为我正在尝试将它添加到右上角。

 content: string = "content of popover ";
 Title: string = "Title of popover";
 <a [popover]="content" container="body" placement="top" [popoverTitle]="Title" >Making this popover</a>
              

This 是我正在使用的链接。我正在使用这个例子,模板和组件。

基本上是我的plunker,简单来说,我需要在标题的右上角有个X。

【问题讨论】:

  • 那是什么问题?
  • 您好,我编辑了我的工作不小心过早地提交了我的帖子,目前尝试在标题的右上角添加一个 x 按钮需要帮助。 @SandipPatel
  • 也许你可以分享更容易帮助的代码。
  • @KarthickManoharan 嗨,我在上面分享了我的代码,够了吗?还是我必须在 plunker 上分享?
  • plunker 会很棒

标签: angular frontend ngx-bootstrap


【解决方案1】:

最终设法做到it,因为popoverTitle 只接受字符串

<div>
  <ng-template #popoverContent3>
    <div style="font-size:18px; font-family:'Times New Roman'; font-weight:bold;">
      <p>this is a title...
      <button type="button" (click)='pop2.hide()' class="close" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      </p>
    </div>
    <div>
     <p>The best looking pop over, with a TITLE!</p>  
    </div>
  </ng-template>
  
  <a  [popover]="popoverContent3" #pop2="bs-popover" placement="right">
   Pop over with title and a x button!
    </a>
</div>

【讨论】:

    【解决方案2】:

    popover dynamic html 文档您可以看到[popover] 接受html 输入。您可以使用 ID 为 eg: #popOverContentng-template 创建具有适当样式的所需自定义弹出框内容,并将 ID 作为输入提供给 [popover],如下所示。

     <a [popover]= "popOverContent" container="body" placement="right">
       this popover need a x on top
     </a>
    
     <ng-template #popOverContent>
       <span style="float:right">X</span>
       <p>Popped content.....</p>
     </ng-template>
    

    您可以在代码中替换这些行以进行更改

    更新:

    您已经在 plnkr 演示中获得了最佳解决方案。 X 可以使用 CSS 样式放置在任何地方。

    <a [popover]="popOverContent" container="body" #pop="bs-popover" 
      placement="right">this popover need a x on top
    </a>
    
    <ng-template #popOverContent>
      <button type="button" (click)='pop.hide()' class="close" aria-
      label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    

    弹出的内容..没有标题

    【讨论】:

    • 是否可以在 X 上使用 hide() 函数
    • 可以用v4-alpha.getbootstrap.com/utilities/close-icon做一个关闭按钮吗?
    • 自己管理它但是我仍然需要一个带标题的 x 按钮,明天继续,谢谢你告诉我使用 ngtemplate,这是我的 plunker。 plnkr.co/edit/urox2SggzTfQfkwJ8rT4?p=info
    • 我仍然无法在标题处制作 x 按钮,使用 ng-template 使标题显示为“object Object”。下面附上我的plunkerembed.plnkr.co/NMjeFv5li5zWe6drBgD2
    • popoverTitle 仅接受 string 数据。在您的示例中,您正在传递一个模板对象,这就是您在标题中看到 [Object Object] 的原因。我也更新了答案
    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2013-04-07
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    相关资源
    最近更新 更多