Angular 2 有一个方法打印出 SVG 多边形的点。

huangapple go评论67阅读模式
英文:

Angular 2 Have method print out svg polygon points

问题

我有一个简单的方法,它会打印一些SVG多边形的点坐标:

printOutSVGFormat() {
    var andrew = "200,10 250,190 160,210";
    return andrew;
}

而模板如下所示:

<div class="svgWalkableArea">
    <svg height="210" width="500">
        <polygon [points]="printOutSVGFormat()" style="fill:lime;stroke:purple;stroke-width:1" />
    </svg>
</div>

然而,Angular 报错如下:

无法绑定到 'points',因为它不是 ':svg:polygon' 的已知属性。

有关如何解决这个问题的想法吗?

英文:

I have a simple method which prints out some svg polygon points:

printOutSVGFormat() {
        var andrew = &quot;200,10 250,190 160,210&quot;;
        return andrew;
    }

And the template is shown below:

&lt;div class=&quot;svgWalkableArea&quot;&gt;
            &lt;svg height=&quot;210&quot; width=&quot;500&quot;&gt;
              &lt;polygon [points]=&quot;printOutSVGFormat()&quot; style=&quot;fill:lime;stroke:purple;stroke-width:1&quot; /&gt;
            &lt;/svg&gt;
          &lt;/div&gt;

However Angular errors with the following code:

Can&#39;t bind to &#39;points&#39; since it isn&#39;t a known property of &#39;:svg:polygon&#39;

Any ideas on how I can get around this?

答案1

得分: 2

尝试 attr.points

<polygon [attr.points]="printOutSVGFormat()" style="fill:lime;stroke:purple;stroke-width:1" />
英文:

Try attr.points

&lt;polygon [attr.points]=&quot;printOutSVGFormat()&quot; style=&quot;fill:lime;stroke:purple;stroke-width:1&quot; /&gt;

huangapple
  • 本文由 发表于 2020年1月6日 21:19:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612865.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定