Skip to content

Commit

Permalink
Merge pull request #43 from czeckd/swapfix
Browse files Browse the repository at this point in the history
Reset differ if svg src changes
  • Loading branch information
czeckd authored Apr 29, 2018
2 parents 1978ee2 + 71b0061 commit 18c43d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 14 additions & 1 deletion lib/src/svg-icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 18c43d6

Please sign in to comment.