【问题标题】:How to programmatically add bootstrap popover to a html element in Angular如何以编程方式将引导弹出窗口添加到 Angular 中的 html 元素
【发布时间】:2018-05-09 07:34:41
【问题描述】:

我的应用:Angular5ng-bootstrapbootstrap 4.0

我正在尝试直接从代码中向 html 元素添加弹出框,而不是通过向元素添加指令。我尝试通过添加 popover() 但函数不存在。这样做的正确方法是什么?

eventRender(model: any, $el) {
    $el.popover({
        title: 'Title',
        content: 'content',
        trigger: 'hover',
        placement: 'top',
        container: 'body'
    });
}

没有写如何以编程方式添加弹出框: https://ng-bootstrap.github.io/#/components/popover/examples

我正在搜索 anwser 一个小时,但我找不到它。我错过了什么,这应该很简单:/

【问题讨论】:

    标签: angular bootstrap-4 popover ng-bootstrap


    【解决方案1】:

    你需要像这样做一些不同的事情。

    import {Component} from '@angular/core'; 
    import {NgbPopoverConfig} from '@ng-bootstrap/ng-bootstrap';
    
    @Component({   selector: 'ngbd-popover-config',   
    templateUrl: './popover-config.html',   
    providers: [NgbPopoverConfig] // add NgbPopoverConfig to the component providers }) 
    
    export class NgbdPopoverConfig {   
    constructor(config: NgbPopoverConfig) {
        // customize default values of popovers used by this component tree
        config.placement = 'right';
        config.triggers = 'hover';   
    } }
    

    【讨论】:

    • 谢谢,现在如何给元素添加弹出框?就像五月的例子一样?
    • ngOnInit(){ $('#Your_element').popover({placement: 'bottom', toggle: 'popover', title: 'Title What you Need' html: true, content: this 。姓名 });这肯定会奏效。在组件之前声明 var $。
    • 我试过了。但它不起作用。您的代码是否用于全局弹出窗口配置?我导入了 jQuery,但它说“$(...).popover 不是函数”。
    • 为什么要动态地将弹出框添加到元素中。您可以在 html 中添加弹出框并更改其配置,或者在需要时以编程方式打开或关闭。
    • 如果我使用 jquery 在 html 中添加弹出框,它不起作用。我想在这个例子中这样做:fullcalendar.io/docs/event-tooltip-demo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多