项目作者: JsDaddy

项目描述 :
Awesome loader for angular applications. No wrappers only you elements
高级语言: TypeScript
项目地址: git://github.com/JsDaddy/ngx-loader-indicator.git
创建时间: 2018-05-15T15:25:38Z
项目社区:https://github.com/JsDaddy/ngx-loader-indicator

开源协议:MIT License

下载



NGX LOADER INDICATOR



NGX LOADER INDICATOR is the best directive to have loader without wrapping your element to additional component

CI
npm
npm downloads

npm

GitHub contributors

GitHub stars

You can also try our NGX MASK check it.
You can also try our NGX COPYPASTE check it.

You can try live demo with examples.

Installing

npm

  1. $ npm install --save ngx-loader-indicator

bun

  1. $ bun install --save ngx-loader-indicator

Quickstart if ngx-loader-indicator version >= 15.0.0

Pay attention this version works for angular >= 14.0.0

Configure for application with provideEnvironmentNgxLoaderIndicator

  1. bootstrapApplication(AppComponent, {
  2. providers: [
  3. provideAnimations(),
  4. provideEnvironmentNgxLoaderIndicator(),
  5. (...)
  6. ],
  7. }).catch((err) => console.error(err));

or configure for feature with provideNgxLoaderIndicator and import standalone directive NgxLoaderIndicatorDirective

  1. @Component({
  2. selector: 'my-feature',
  3. templateUrl: './my-feature.component.html',
  4. styleUrls: ['./my-feature.component.css'],
  5. standalone: true,
  6. imports: [NgxLoaderIndicatorDirective, (...)],
  7. providers: [
  8. (...)
  9. provideNgxLoaderIndicator({
  10. img: 'https://avatars2.githubusercontent.com/u/32452610?s=200&v=4',
  11. loaderStyles: {
  12. background: 'rgba(255, 255, 255, 0.8)',
  13. },
  14. imgStyles: {
  15. width: '50px',
  16. background: 'yellow',
  17. },
  18. rotate: {
  19. duration: 5000,
  20. },
  21. }),
  22. ],
  23. })
  24. export class MyFeatureComponent {}

Quickstart if ngx-loader-indicator version < 15.0.0

Pay attention this version works for angular < 12.0.0

Import module in needed module.

  1. import {NgxLoaderIndicatorModule} from 'ngx-loader-indicator'
  2. (...)
  3. @NgModule({
  4. (...)
  5. imports: [
  6. NgxLoaderIndicatorModule.forRoot(options)
  7. ]
  8. (...)
  9. })

Usage

  1. <div [ngxLoaderIndicator]="isLoading">Content</div>

Examples

  1. <form (ngSubmit)="save(form.value)" [formGroup]="form" [ngxLoaderIndicator]="isLoading">
  2. <h2>Login</h2>
  3. <input matInput type="email" placeholder="Email" #email formControlName="email" />
  4. <input matInput type="password" placeholder="Password" #name formControlName="password" />
  5. <button mat-button [disabled]="form.invalid">Login</button>
  6. </form>

Options

You can define your custom options

custom img (string) and colors

  1. {
  2. img: string,
  3. imgStyles: {
  4. width: string, // '30px'
  5. background: string, // 'yellow' or rgb(255, 255, 0)
  6. }
  7. }

custom wrapper layout colors

  1. {
  2. loaderStyles: {
  3. background: string,
  4. },
  5. }

animations options for image rotation

  1. rotate: {
  2. delay?: number;
  3. direction?: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
  4. duration: number
  5. easing?: string;
  6. endDelay?: number;
  7. fill?: 'none' | 'forwards' | 'backwards' | 'both' | 'auto';
  8. id?: string;
  9. iterationStart?: number;
  10. iterations?: number;
  11. },

Usage

  1. import {NgxLoaderIndicatorModule} from 'ngx-loader-indicator'
  2. (...)
  3. @NgModule({
  4. (...)
  5. imports: [
  6. NgxLoaderIndicatorModule.forRoot({
  7. img: 'https://avatars2.githubusercontent.com/u/32452610?s=200&v=4',
  8. loaderStyles: {
  9. background: 'rgba(255, 255, 255, 0.8)',
  10. },
  11. imgStyles: {
  12. width: '100px',
  13. background: 'yellow',
  14. },
  15. rotate: {
  16. duration: 5000
  17. },
  18. }),
  19. ]
  20. (...)
  21. })