angular-docs-cn/aio/content/guide/svg-in-templates.md

974 B

SVG as templates

You can use SVG files as templates in your Angular applications. When you use an SVG as the template, you are able to use directives and bindings just like with HTML templates. With these features, you can dynamically generate interactive graphics.

See the for a working example containing the code snippets in this guide.

SVG syntax example

The following example shows the syntax for using an SVG as a template.

To see property and event binding in action, add the following code to your svg.component.svg file:

The example given uses a click() event binding and the property binding syntax ([attr.fill]="fillColor").