Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset differ if svg src changes #43

Merged
merged 1 commit into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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