【发布时间】:2020-05-23 09:32:30
【问题描述】:
在我的 Angular 9 应用程序中,我需要将 svg 文件添加为交互式图像。
svg 本身位于my-file.svg 中,如下所示:
<svg>
<polygon class="my-polygon-class" points="31.7793,138.705 39.7885,138.705 39.7885,128.848 31.7793,128.848 "/>
<!-- lots of other polygons and paths -->
</svg>
我有一个组件:
@Component({
selector: 'car-view',
templateUrl: './car-view.component.html',
styleUrls: ['./car-view.component.scss']
})
export class CarViewComponent {
constructor() {
}
elementClicked() {
}
}
在car-view.component.html 中,我将此 svg 包含为:
<div class="car-view">
<object data="../assets/my-file.svg" type="image/svg+xml"></object>
</div>
如何在my-polygon-class(位于 svg 内)的点击事件中调用 CarViewComponent 内的 elementClicked() 函数?我还需要切换另一个类(比如element-clicked),以便将 svg 多边形标记为已单击。
【问题讨论】:
标签: javascript html angular svg