-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from czeckd/stringloader
Update for Angular 6 and add function to load SVG from string.
- Loading branch information
Showing
10 changed files
with
222 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,25 @@ | |
Angular SVG Icon | ||
========= | ||
|
||
The **angular-svg-icon** is an Angular 4.3+ service and component that provides a | ||
The **angular-svg-icon** is an Angular 6 service and component that provides a | ||
means to inline SVG files to allow for them to be easily styled by CSS and code. | ||
|
||
The service provides an icon registery that loads and caches a SVG indexed by | ||
its url. The component is responsible for displaying the SVG. After getting the | ||
svg from the registry it clones the `SVGElement` and the SVG to the component's | ||
inner HTML. | ||
|
||
A [working demo](http://czeckd.github.io/angular-svg-icon/demo/) shows solution in action. | ||
This [demo](http://czeckd.github.io/angular-svg-icon/demo/) shows this module in action. | ||
|
||
## How to use? | ||
``` | ||
$ npm i angular-svg-icon --save | ||
``` | ||
(**Note:** For use Angular 2.4 through Angular 4.2, please install [email protected] | ||
and see the module's accompanying README.md for instructions.) | ||
**Note on earlier versions of ngx:** | ||
- For Angular 4.3 through Angular 5.x, use [email protected] | ||
- For Angular 2.4 through Angular 4.2, use [email protected] | ||
|
||
See the module's accompanying README.md for instructions. | ||
|
||
## Integration | ||
|
||
|
@@ -30,8 +33,8 @@ import { HttpClientModule } from '@angular/common/http'; | |
import { AngularSvgIconModule } from 'angular-svg-icon'; | ||
|
||
@NgModule({ | ||
imports: [ HttpClientModule, AngularSvgIconModule ], | ||
... | ||
imports: [ HttpClientModule, AngularSvgIconModule ], | ||
... | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
@@ -60,23 +63,29 @@ Include the ``private iconReg:SvgIconRegistryService`` in the constructor: | |
constructor(private iconReg:SvgIconRegistryService) { } | ||
``` | ||
|
||
The registry has two public functions: `loadSvg(string)` and `unloadSvg(string)`. | ||
|
||
To preload a svg file into the registry: | ||
The registry has three public functions: `loadSvg(string)`, `addSvg(string, string)`, and `unloadSvg(string)`. | ||
|
||
To preload a SVG file from a URL into the registry: | ||
```typescript | ||
{ | ||
... | ||
this.iconReg.loadSvg('foo.svg'); | ||
... | ||
this.iconReg.loadSvg('foo.svg'); | ||
} | ||
``` | ||
|
||
To unload a svg from the registry. | ||
|
||
To add a SVG from a sting: | ||
```typescript | ||
{ | ||
... | ||
this.iconReg.addSvg('box', | ||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M1 1 L1 9 L9 9 L9 1 Z"/></svg>' | ||
); | ||
} | ||
``` | ||
To unload a SVG from the registry. | ||
```typescript | ||
{ | ||
... | ||
this.iconReg.unloadSvg('foo.svg'); | ||
... | ||
this.iconReg.unloadSvg('foo.svg'); | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,65 @@ | ||
(function(global) { | ||
|
||
var ngVer = '@5.0.0'; | ||
|
||
var paths = { | ||
'npm:' : 'https://unpkg.com/' | ||
} | ||
|
||
// map tells the System loader where to look for things | ||
var map = { | ||
'app': 'app', | ||
'angular-svg-icon': 'lib', | ||
'rxjs': 'npm:[email protected]', | ||
'tslib': 'npm:[email protected]', | ||
'typescript' : 'npm:[email protected]/lib/typescript.js', | ||
|
||
'@angular/core': 'npm:@angular/core/bundles/core.umd.js', | ||
'@angular/common': 'npm:@angular/common/bundles/common.umd.js', | ||
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js', | ||
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', | ||
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', | ||
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', | ||
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js' | ||
}; | ||
|
||
// packages tells the System loader how to load when no filename and/or no extension | ||
var packages = { | ||
'app': { main: 'main.ts', defaultExtension: 'ts' }, | ||
'angular-svg-icon': { main: 'index.ts', defaultExtension: 'ts' }, | ||
|
||
'rxjs': { defaultExtension: 'js' }, | ||
'tslib': { main: 'tslib.js', defaultExtension: 'js' } | ||
}; | ||
|
||
var config = { | ||
transpiler: 'typescript', | ||
typescriptOptions: { | ||
sourceMap: true, | ||
emitDecoratorMetadata: true, | ||
experimentalDecorators: true | ||
}, | ||
meta: { | ||
typescript: { exports: 'ts' } | ||
}, | ||
paths: paths, | ||
map: map, | ||
packages: packages | ||
} | ||
|
||
// filterSystemConfig - index.html's chance to modify config before it is registered. | ||
if (global.filterSystemConfig) { | ||
global.filterSystemConfig(config); | ||
} | ||
|
||
System.config(config); | ||
var ngVer = '@6.0.0'; | ||
|
||
var paths = { | ||
'npm:' : 'https://unpkg.com/' | ||
} | ||
|
||
// map tells the System loader where to look for things | ||
var map = { | ||
'app': 'app', | ||
'angular-svg-icon': 'lib', | ||
'rxjs': 'npm:[email protected]', | ||
'rxjs/operators': 'npm:[email protected]/operators', | ||
'tslib': 'npm:[email protected]', | ||
'typescript' : 'npm:[email protected]/lib/typescript.js', | ||
|
||
'@angular/core': 'npm:@angular/core/bundles/core.umd.js', | ||
'@angular/common': 'npm:@angular/common/bundles/common.umd.js', | ||
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js', | ||
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', | ||
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', | ||
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', | ||
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js' | ||
}; | ||
|
||
// packages tells the System loader how to load when no filename and/or no extension | ||
var packages = { | ||
'app': { main: 'main.ts', defaultExtension: 'ts' }, | ||
'angular-svg-icon': { main: 'index.ts', defaultExtension: 'ts' }, | ||
|
||
'rxjs': { | ||
'main': 'index.js', | ||
'defaultExtension': 'js' | ||
}, | ||
'rxjs/operators': { | ||
'main': 'index.js', | ||
'defaultExtension': 'js' | ||
}, | ||
'tslib': { main: 'tslib.js', defaultExtension: 'js' } | ||
}; | ||
|
||
var config = { | ||
transpiler: 'typescript', | ||
typescriptOptions: { | ||
sourceMap: true, | ||
emitDecoratorMetadata: true, | ||
experimentalDecorators: true | ||
}, | ||
meta: { | ||
typescript: { exports: 'ts' } | ||
}, | ||
paths: paths, | ||
map: map, | ||
packages: packages | ||
} | ||
|
||
// filterSystemConfig - index.html's chance to modify config before it is registered. | ||
if (global.filterSystemConfig) { | ||
global.filterSystemConfig(config); | ||
} | ||
|
||
System.config(config); | ||
|
||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.