Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从javascript触发工具提示?_Javascript_Angular_Ngx Bootstrap - Fatal编程技术网

如何从javascript触发工具提示?

如何从javascript触发工具提示?,javascript,angular,ngx-bootstrap,Javascript,Angular,Ngx Bootstrap,我试图从javascript触发ngx引导工具提示。下面的代码工作没有任何问题。现在我想从javascript端手动调用show()函数 问题是我不知道什么是“bs工具提示”。它是ngx引导创建的元素的id。如果是这样的话,我如何从javascript中获取该元素 尝试使用viewChild访问组件类中的customTooltip: import { ViewChild } from '@angular/core'; export class YourComponent { @Vie

我试图从javascript触发ngx引导工具提示。下面的代码工作没有任何问题。现在我想从javascript端手动调用show()函数

问题是我不知道什么是“bs工具提示”。它是ngx引导创建的元素的id。如果是这样的话,我如何从javascript中获取该元素


尝试使用
viewChild
访问组件类中的
customTooltip

import { ViewChild } from '@angular/core';

export class YourComponent {
    @ViewChild('customTooltip') tooltip: ElementRef;
    onClick() {
        this.tooltip.show();
    }
}

<span #customTooltip="bs-tooltip" tooltip="Hello there! I was triggered manually" triggers="" > This text has attached tooltip</span>
从'@angular/core'导入{ViewChild};
导出类组件{
@ViewChild('customTooltip')工具提示:ElementRef;
onClick(){
this.tooltip.show();
}
}
此文本已附加工具提示

您的代码运行正常,但我发现“类型'ElementRef'上不存在属性'show'。”错误。有没有办法处理此错误?请尝试为tooltip元素指定一个类型:
import{TooltipDirective}from'ngx bootstrap'
@ViewChild('customTooltip')工具提示:工具提示指令
document.getElementById("bs-tooltip")  //returns null
import { ViewChild } from '@angular/core';

export class YourComponent {
    @ViewChild('customTooltip') tooltip: ElementRef;
    onClick() {
        this.tooltip.show();
    }
}

<span #customTooltip="bs-tooltip" tooltip="Hello there! I was triggered manually" triggers="" > This text has attached tooltip</span>