Package Exports
- @ng-util/lazy
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ng-util/lazy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@ng-util/lazy
Lazy load javascript, css resources for Angular.
Demo
Usage
import { Component } from '@angular/core';
import { NuLazyService } from '@ng-util/lazy';
@Component({
selector: 'app-demo',
template: ` <button *ngIf="loaded" type="button" class="btn btn-primary">Primary</button>`,
})
export class DemoComponent {
loaded = false;
constructor(private srv: NuLazyService) {
this.load();
}
async load() {
await this.srv.load([
`https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css`,
`https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.bundle.min.js`,
]);
this.loaded = true;
}
}API
| name | type | description |
|---|---|---|
events |
Observable<NuLazyResult[]> |
Events change callback |
clear() |
void |
Clean all cached items |
load(paths: string | string[]) |
Promise<NuLazyResult[]> |
Load the specified resources, includes .js, .css |
loadScript(path: string, options?: { innerContent?: string }) |
Promise<NuLazyResult> |
Load a script resources |
loadStyle(path: string, options?: { ref?: string, innerContent?: string }) |
Promise<NuLazyResult> |
Load a style resources |
License
The MIT License (see the LICENSE file for the full text)