gpt4 book ai didi

angular - SVG foreignObject 未显示在 Angular 模板内

转载 作者:行者123 更新时间:2023-12-04 10:24:04 28 4
gpt4 key购买 nike

我在 Angular9 组件模板中使用内联 SVG。我想在这个 SVG 中显示一个 HTML 元素。当我尝试在其中使用 SVG foreignObject 时,它不会显示。

<p>Inline SVG with foreignobject inside angular component:</p>
<svg xmlns="http://www.w3.org/2000/svg" width="200px" height="100px">
<rect x="0" y="0" width="100%" height="100%" fill="yellow"/>
<foreignobject x="10" y="10" width="100px" height="50px" >
<xhtml:div xmlns="http://www.w3.org/1999/xhtml" style="background-color: aqua;">
foreign object
</xhtml:div>
</foreignobject>
</svg>

当我在其他地方使用相同的 SVG 代码时,它正在工作。例如,当我直接在 index.html 中插入以下代码(不是在 angular 组件中)时,它会正确显示:
<p>SVG with foreignobject in index.html (not in angular component):</p>
<svg xmlns="http://www.w3.org/2000/svg" width="200px" height="100px">
<rect x="0" y="0" width="100%" height="100%" fill="yellow"/>
<foreignobject x="10" y="10" width="100px" height="50px" >
<div xmlns="http://www.w3.org/1999/xhtml" style="background-color: aqua;">
foreign object
</div>
</svg:foreignobject>
</svg>

我遗漏了什么,或者它是 Angular 内部的错误?请参见此处的示例: https://stackblitz.com/edit/angular-frdbxq

最佳答案

如果是 Angular 模板,你应该注意区分大小写的标签方式:

<foreignobject 
||
\/
<foreignObject
Forked Stackblitz

关于angular - SVG foreignObject 未显示在 Angular 模板内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60703834/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com