Skip to content
This repository has been archived by the owner on May 23, 2020. It is now read-only.

Commit

Permalink
Add onSVGFailed EventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
echeung-amzn committed Dec 9, 2016
1 parent 2db99e1 commit 6c3e3a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ The SVG file (if found) will be inserted *inside* the element with the `[inlineS
| Property name | Callback arguments | Description |
| ------------- | ------------------ | ----------- |
| onSVGInserted | `e: SVGElement` | Emits the `SVGElement` post-insertion. |
| onSVGFailed | `e: any` | Emits when there is some error (e.g. embed SVG not supported, fetch failed, etc.) |
13 changes: 4 additions & 9 deletions src/inline-svg.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class InlineSVGDirective implements OnInit, OnChanges {
@Input() removeSVGAttributes: Array<string>;

@Output() onSVGInserted: EventEmitter<SVGElement> = new EventEmitter<SVGElement>();
@Output() onSVGFailed: EventEmitter<any> = new EventEmitter<any>();

/** @internal */
private _absUrl: string;
Expand All @@ -49,17 +50,13 @@ export class InlineSVGDirective implements OnInit, OnChanges {
private _insertSVG(): void {
// Check if the browser supports embed SVGs
if (!this._supportSVG()) {
if (window.console) {
console.error('Your browser does not support embed SVGs');
}
this.onSVGFailed.emit('Embed SVG not supported by browser');
return;
}

// Check if a URL was actually passed into the directive
if (!this.inlineSVG) {
if (window.console) {
console.error('No URL passed to [inlineSVG]!');
}
this.onSVGFailed.emit('No URL passed to [inlineSVG]');
return;
}

Expand Down Expand Up @@ -111,9 +108,7 @@ export class InlineSVGDirective implements OnInit, OnChanges {
}
},
(err: any) => {
if (window.console) {
console.error(err);
}
this.onSVGFailed.emit(err);
}
);
}
Expand Down

0 comments on commit 6c3e3a1

Please sign in to comment.