1.0.2 • Published 7 years ago
ng-script-loader v1.0.2
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-devWith Yarn:
yarn add ng-script-loaderSetup
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),
    )
  }
}