-
Notifications
You must be signed in to change notification settings - Fork 40
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 #33 from czeckd/ng5
Use HttpClient
- Loading branch information
Showing
11 changed files
with
170 additions
and
179 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 |
---|---|---|
@@ -1,35 +1,36 @@ | ||
[![npm version](https://badge.fury.io/js/angular-svg-icon.svg)](https://badge.fury.io/js/angular-svg-icon) | ||
|
||
Angular SVG Icon | ||
Angular SVG Icon | ||
========= | ||
|
||
The **angular-svg-icon** is an Angular 2+ service and component that provides a | ||
means to inline SVG images to allow for them to be easily styled by CSS and | ||
code. | ||
The **angular-svg-icon** is an Angular 4.3+ 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 | ||
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. | ||
A [working demo](http://czeckd.github.io/angular-svg-icon/demo/) shows solution 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.) | ||
|
||
## Integration | ||
|
||
The **angular-svg-icon** should work as-is with webpack/angular-cli. Just add | ||
the ``AngularSvgIconModule``. | ||
The **angular-svg-icon** should work as-is with webpack/angular-cli. Just import the | ||
``AngularSvgIconModule`` and the ```HttpClientModule```. | ||
|
||
```typescript | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { AngularSvgIconModule } from 'angular-svg-icon'; | ||
|
||
@NgModule({ | ||
imports: [ AngularSvgIconModule ], | ||
imports: [ HttpClientModule, AngularSvgIconModule ], | ||
... | ||
}) | ||
export class AppModule {} | ||
|
@@ -52,14 +53,14 @@ constructor(private iconReg:SvgIconRegistryService) { } | |
|
||
The registry has two public functions: `loadSvg(string)` and `unloadSvg(string)`. | ||
|
||
To preload a svg file into the registry: | ||
To preload a svg file into the registry: | ||
|
||
```typescript | ||
{ | ||
... | ||
this.iconReg.loadSvg('foo.svg'); | ||
} | ||
``` | ||
``` | ||
|
||
To unload a svg from the registry. | ||
|
||
|
@@ -70,22 +71,29 @@ To unload a svg from the registry. | |
} | ||
``` | ||
|
||
## SVG Preparation | ||
The SVG should be modified to remove the height and width attributes from the file | ||
per Sara Soueidan's advice in "[Making SVGs Responsive With | ||
CSS](http://tympanus.net/codrops/2014/08/19/making-svgs-responsive-with-css/)" if | ||
size is to be modified through CSS. Removing the height and width has two immedate | ||
impacts: (1) CSS can be used to size the SVG, and (2) CSS will be *required* to | ||
size the SVG. | ||
|
||
## Background | ||
|
||
The svg-icon is an Angular 2 component that allows for the continuation of the | ||
AngularJS method for easily inlining SVGs explained by [Ben | ||
Markowitz](https://www.mobomo.com/2014/09/angular-js-svg/) and others. Including | ||
The svg-icon is an Angular 2 component that allows for the continuation of the | ||
AngularJS method for easily inlining SVGs explained by [Ben | ||
Markowitz](https://www.mobomo.com/2014/09/angular-js-svg/) and others. Including | ||
the SVG source inline allows for the graphic to be easily styled by CSS. | ||
|
||
The technique made use of ng-include to inline the svg source into the document. | ||
Angular 2, however, drops the support of ng-include, so this is my work-around | ||
The technique made use of ng-include to inline the svg source into the document. | ||
Angular 2, however, drops the support of ng-include, so this is my work-around | ||
method. | ||
|
||
*Note:* The [icon | ||
component](https://www.npmjs.com/package/@angular2-material/icon) from | ||
[angular/material2](https://github.com/angular/material2) used to have a direct | ||
means to load svg similar to this, but this functionality was removed because of | ||
*Note:* The [icon | ||
component](https://www.npmjs.com/package/@angular2-material/icon) from | ||
[angular/material2](https://github.com/angular/material2) used to have a direct | ||
means to load svg similar to this, but this functionality was removed because of | ||
security concerns. | ||
|
||
## License | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
<!-- Polyfill(s) for older browsers --> | ||
<script src="https://unpkg.com/core-js/client/shim.min.js"></script> | ||
|
||
<script src="https://unpkg.com/[email protected].4?main=browser"></script> | ||
<script src="https://unpkg.com/[email protected].18?main=browser"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/system.src.js"></script> | ||
|
||
<script src="demo/systemjs.config.js"></script> | ||
|
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,61 +1,57 @@ | ||
(function(global) { | ||
|
||
var ngVer = '@4.0.0'; | ||
|
||
var paths = { | ||
'npm:' : 'https://unpkg.com/' | ||
} | ||
|
||
// map tells the System loader where to look for things | ||
var map = { | ||
'app': 'app', | ||
'rxjs': 'npm:[email protected]', | ||
'@angular': 'npm:@angular', | ||
'typescript' : 'npm:[email protected]/lib/typescript.js', | ||
'angular-svg-icon': 'lib' | ||
}; | ||
|
||
// packages tells the System loader how to load when no filename and/or no extension | ||
var packages = { | ||
'app': { main: 'main.ts', defaultExtension: 'ts' }, | ||
'rxjs': { defaultExtension: 'js' }, | ||
'angular-svg-icon': { main: 'index.ts', defaultExtension: 'ts' } | ||
}; | ||
|
||
var ngPackageNames = [ | ||
'common', | ||
'compiler', | ||
'core', | ||
'forms', | ||
'http', | ||
'platform-browser', | ||
'platform-browser-dynamic' | ||
]; | ||
|
||
ngPackageNames.forEach(function(pkgName) { | ||
map['@angular/'+pkgName] = 'npm:@angular/' + pkgName + ngVer; | ||
}); | ||
|
||
// Add package entries for angular packages | ||
ngPackageNames.forEach(function(pkgName) { | ||
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' }; | ||
}); | ||
|
||
var config = { | ||
transpiler: 'typescript', | ||
typescriptOptions: { | ||
emitDecoratorMetadata: true | ||
}, | ||
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 = '@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); | ||
|
||
})(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
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.