jquery - 如何在 jQuery mouseover 中调用 Angular 方法?
问题描述
我正在使用 Angular 8。我正在阅读一个 svg 文件并查找样式为 has 的元素stroke:none
。然后,每当有人将鼠标悬停在该元素上时,我都会打开一个对话框。
我需要在 jQuery mouseover 中打开 Angular Material 对话框。此警报有效但this.openDialog()
无效。
这给了我这个错误:
未捕获的类型错误:component.openDialog 不是函数
主要组件.ts
openDialog() {
const dialogRef = this.dialog.open(DialogBoxComponent, {
height: '100px',
width: '450px',
});
}
myfunction() {
const mySVG: any = document.getElementById('svg-object');
mySVG.addEventListener('load',() => {
svgDoc = mySVG.contentDocument;
$(svgDoc).find('path').css('fill','fill-opacity','fill-rule','stroke').each(function() {
const style = $(this).attr('style');
if($(this).attr('style').includes('stroke:none')) {
const component = this;
$(this).mouseover(() => {
component.openDialog();
alert('HELLO');
});
}
});
}, false);
}
对话框组件.ts
constructor(public dialogRef: MatDialogRef<MainComponent>) {
}
onNoClick(): void {
this.dialogRef.close();
}
对话框组件.html
<h3 mat-dialog-title>TOPIC</h3>
<div class="container">
<div class="device-config-main-container d-flex flex-column">
</div>
<div mat-dialog-actions>
<button mat-button mat-dialog-close (click)="onNoClick()">Close</button>
</div>
</div>
解决方案
推荐阅读
- php - curl_multi_exec - 部分请求返回 CURLE_COULDNT_RESOLVE_HOST
- c# - 注册 SPO 中心网站 CSOM
- php - 在 Twig 中构建有效的 json 对象
- android - Cordova:某些输入文件使用或覆盖已弃用的 API
- python - PyMysql-Python:如何检查用户提供的输入是否存在于我的数据库中
- r - 阻止 R as.h2o 加载将空白转换为 NA
- amazon-web-services - Cognito 用户池中的自定义属性是否适合存储动态用户信息?
- php - 如何获得“publish_post”等价物
- ios - iOS UICollectionView 与垂直 UICollectionView 单元格内的水平滚动重用
- javascript - 我可以为自己的变量调用 $.fn 函数吗?