在 HTML 节点上设置 Angular2 样式的属性

Setting Angular2-style attributes on HTML node

我正在将应用程序从 Angular1 迁移到 Angular2,其中我使用 svg.js 库绘制 SVG。 SVG 的一些元素包含 "ng-click" 指令,我将 SVG 库打印到最终的 SVG。

这在 Angular1 中工作正常,但是,现在该指令被称为“(click)”并且一切都中断了。我追踪了 SVG 来源,发现下面的调用

this.node.setAttribute(attr, value.toString())

导致以下错误消息:

VM22161:1 Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '(click)' is not a valid attribute name.(…)

有解决这个问题的想法吗?如果没有其他办法,修补 SVG 源对我来说就可以了。

一个有效且快速的解决方法是使用 Angular2 的绑定语法,它允许使用 "on-click" 而不是“(click)”。