diff --git a/lib/package.json b/lib/package.json index c80b8d1..2dbaf36 100644 --- a/lib/package.json +++ b/lib/package.json @@ -2,7 +2,7 @@ "$schema": "../../node_modules/ng-packagr/package.schema.json", "name": "angular-svg-icon", "description": "Angular 5 component for inlining SVGs allowing them to be easily styled with CSS.", - "version": "5.1.0", + "version": "5.1.1", "repository": { "type": "git", "url": "https://github.com/czeckd/angular-svg-icon.git" diff --git a/lib/src/svg-icon.component.ts b/lib/src/svg-icon.component.ts index ba3d849..166905c 100644 --- a/lib/src/svg-icon.component.ts +++ b/lib/src/svg-icon.component.ts @@ -47,7 +47,9 @@ export class SvgIconComponent implements OnInit, OnDestroy, OnChanges, DoCheck { ngOnChanges(changeRecord: {[key:string]:SimpleChange}) { if (changeRecord['src']) { - this.destroy(); + if (this.svg) { + this.destroy(); + } this.init(); } if (changeRecord['stretch']) { @@ -67,15 +69,26 @@ export class SvgIconComponent implements OnInit, OnDestroy, OnChanges, DoCheck { private init() { this.icnSub = this.iconReg.loadSvg(this.src).subscribe(svg => { this.setSvg(svg); + this.resetDiffer(); }); } private destroy() { + this.svg = undefined; + this.differ = undefined; if (this.icnSub) { this.icnSub.unsubscribe(); } } + private resetDiffer() { + if (this._svgStyle) { + if (!this.differ) { + this.differ = this.differs.find(this._svgStyle).create(); + } + } + } + private setSvg(svg:SVGElement) { if (svg) { this.svg = svg; diff --git a/package.json b/package.json index 29e887f..100669a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angular-svg-icon", "description": "Angular 5 component for inlining SVGs allowing them to be easily styled with CSS.", - "version": "5.1.0", + "version": "5.1.1", "repository": { "type": "git", "url": "https://github.com/czeckd/angular-svg-icon.git"