Skip to content

Commit b3342a5

Browse files
committed
Change readme
1 parent 1ced048 commit b3342a5

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,44 @@ Using npm:
99
npm i --save @ueler/ng-lazyload-script
1010
```
1111

12+
## Features
13+
- Provides an Angular service to load javascript files.
14+
- The service loads each library only once, i.e. remembers which libraries were already loaded.
15+
- You can subscribe to the returned observable to execute code relying on the lazy loaded script.
16+
17+
## How does it work?
18+
The service creates a ``<script>`` tag with the provided source url and appends it to the document body.
19+
20+
## Usage
21+
1\. Inject the service into your own service or component:
22+
```
23+
constructor(private ngLazyloadScriptService: NgLazyloadScriptService) {
24+
}
25+
```
26+
27+
2\. Use the service to load an external javascript library (like Google Maps JS API or Stripe JS API).
28+
3\. Subscribe to the observable and use the loaded library on success case.
29+
```
30+
this.ngLazyloadScriptService.loadScript('URL_TO_JAVASCRIPT_FILE').subscribe(() => {
31+
// success case: do something with the loaded library
32+
}, () => {
33+
// error case
34+
});
35+
```
36+
37+
38+
## Example
39+
It can be used to load the Stripe Javscript API (https://stripe.com/docs/js):
40+
```
41+
this.ngLazyloadScriptService.loadScript('https://js.stripe.com/v3/').subscribe(() => {
42+
// use Stripe constructor from loaded library
43+
const stripe = Stripe('stripe_public_key', {
44+
betas: ['payment_intent_beta_3']
45+
});
46+
47+
// ...
48+
});
49+
```
50+
51+
## Compatibility
52+
The library works with Angular versions ``>=8.0.0``.

projects/ng-lazyload-script/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@ueler/ng-lazyload-script",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"peerDependencies": {
5-
"@angular/core": ">=7.0.0",
5+
"@angular/core": ">=8.0.0",
66
"rxjs": ">=6.0.0"
77
},
88
"description": "Load external javascript libraries/files (e.g. Google Maps JavaScript API, Stripe JavaScript API, ...) in your components and services on the fly (when you need them) and execute code as soon as it's loaded.",

0 commit comments

Comments
 (0)