ng-script-loader

1.0.2 • Public • Published

ng-script-loader - Another Angular Script Loader

ng-script-loader is a very simple external script loader for Angular 6+. You can use it to load 3rd part scripts dynamically, or settings from your server.

Installation

With NPM:

npm install ng-script-loader --save-dev

With Yarn:

yarn add ng-script-loader

Setup

Import ScriptLoaderModule into your application

import { ScriptLoaderModule } from 'ng-script-loader';

@NgModule({
  ...
  imports: [
    ...
    ScriptLoaderModule
  ]
})

Usage

import { ScriptLoaderService, Script } from 'ng-script-loader';

@Component({})
export class ExampleComponent implements OnInit {
  constructor(
    private scriptLoader: ScriptLoaderService
  ) {}

  ngOnInit() {
    const script: Script = {
      name: 'example',
      src: 'https://example.com/path/to/script.js'
    };
    this.scriptLoader.load(script).pipe(
      skipWhile(s = !s.loaded),

    )
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i ng-script-loader

Weekly Downloads

8

Version

1.0.2

License

none

Unpacked Size

7.3 kB

Total Files

21

Last publish

Collaborators

  • ankemp