I am using Angular 8. I am reading a svg file and find elements with style has stroke:none. Then open a dialog box whenever someone hover that element. Dialog box is opening but it is not closing when I click on outside or close button.
I tried that same dialog box to the button id="btn" and it is closing successfully.
There are no errors coming.
main.component.html
<object id="svg-object" data="assets/svg/xxx.svg" type="image/svg+xml"></object>
<button mat-button id="btn">Launch dialog</button>
main.component.ts
ngOnInit() {
this.myfunction();
$('#btn').mouseover(() => {
this.openDialog();
});
}
openDialog() {
const dialogRef = this.dialog.open(DialogBoxComponent, {
height: '100px',
width: '450px',
});
}
myfunction() {
const component = this;
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')) {
$(this).mouseover(() => {
component.openDialog();
});
}
});
}, false);
}
DialogBoxComponent.ts
constructor(public dialogRef: MatDialogRef<MainComponent>) {
}
onNoClick(): void {
this.dialogRef.close();
}
DialogBoxComponent.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-raised-button matDialogClose (click)="onNoClick()">Close</button>
</div>
</div>
Below button hover dialog box closing is working successfully:
$('#btn').mouseover(() => {
this.openDialog();
});