How to create an SVG component dynamically in Angular2?

后端 未结 3 942
灰色年华
灰色年华 2021-01-06 10:09

I am creating a web application which uses SVG. I have created components consist of SVG element, and they are put into a root svg element. They have attribute

3条回答
  •  悲&欢浪女
    2021-01-06 11:04

    Instead of trying to create your component to the view with the Component Resolver I will do this instead.

    • Create a object with properties which match the attributes you want to pass to your SVG Component.
    • Append this object to an array (ex.svgItems).
    • Add *ngFor="svgItem in svgItems" to the SVG component you want to create dynamically.

    Hope it's clear and solve your problem.

提交回复
热议问题