如何从javascript触发工具提示?
我试图从javascript触发ngx引导工具提示。下面的代码工作没有任何问题。现在我想从javascript端手动调用show()函数 问题是我不知道什么是“bs工具提示”。它是ngx引导创建的元素的id。如果是这样的话,我如何从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
尝试使用
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>