【发布时间】:2019-04-08 17:03:24
【问题描述】:
在一个组件中,我在模板中有一个 svg 渲染,并会对其进行操作以放置一些图形。实际上,我无法使用 nativeElement 或 HTMLElement 访问 svg 文档。
模板是:
template:
`<div>
<object data="/assets/deploiement.svg" type="image/svg+xml" height="450" width="650" #dataSvg >
</object>
</div>`,
我想实现的例子:
ngAfterViewInit() {
const elemnentRef = this.dataSvg;
console.log(elemnentRef.);
const circle = '<circle cx="500" cy="50" r="65" />';
( this.state === 2 ) {
this.dataSvg.nativeElement.svg.append(circle) ;
}
}
【问题讨论】:
-
你为什么要使用
object标签而不是svg标签? -
我使用对象根据对象的状态加载外部 svg
-
您可以使用 svg 标签来做到这一点。还有其他原因吗?