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

1.5 KiB

SVG in templates

Marked for archiving

To ensure that you have the best experience possible, this topic is marked for archiving until we determine that it clearly conveys the most accurate information possible.

If you think this content should not be archived, please file a GitHub issue.

It is possible to use SVG as valid templates in Angular. All of the template syntax below is applicable to both SVG and HTML. Learn more in the SVG 1.1 and 2.0 specifications.

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

Why would you use SVG as template, instead of simply adding it as image to your application?

When you use an SVG as the template, you are able to use directives and bindings just like with HTML templates. This means that you will be able to dynamically generate interactive graphics.

Refer to the sample code snippet below for a syntax example:

Add the following code to your svg.component.svg file:

Here you can see the use of a click() event binding and the property binding syntax ([attr.fill]="fillColor").