Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Fixed support for symbols ID which are not numbers (#98)
Browse files Browse the repository at this point in the history
* Support for ID that are numbers

https://stackoverflow.com/a/20306218/532695

* Fixed missing )

* fixed the attribute name

* Raise an exception if a symbol is not found

Prevent from crashing in the case we specified a wrong fragment for a symbol name.
For instance an svg has a symbol abcd, if I specified `someUrl/my.svg#defg` it will fail using the onSVGFail error emitter.
  • Loading branch information
Xample authored and arkon committed Dec 28, 2018
1 parent 86bb520 commit d0843be
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/inline-svg.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,18 @@ export class InlineSVGDirective implements OnInit, OnChanges, OnDestroy {
.subscribe(
(svg: SVGElement) => {
if (this._isUrlSymbol(this.inlineSVG)) {
const symbolId = '#' + this.inlineSVG.split('#')[1];

const symbolId = this.inlineSVG.split('#')[1];
const symbolSelector = '#' + symbolId;
const elSvg = this._renderer.createElement('svg', 'svg');
this._renderer.appendChild(elSvg, svg.querySelector(symbolId));
const symbol = svg.querySelector("[id='"+symbolId+"']");
if (!symbol){
this._fail('No symbol:'+symbolId+' found');
return;
}
this._renderer.appendChild(elSvg, symbol);

const elSvgUse = this._renderer.createElement('use', 'svg');
this._renderer.setAttribute(elSvgUse, 'href', symbolId, 'xlink');
this._renderer.setAttribute(elSvgUse, 'href', symbolSelector, 'xlink');
this._renderer.appendChild(elSvg, elSvgUse);

this._processSvg(elSvg);
Expand Down

0 comments on commit d0843be

Please sign in to comment.