JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 52
  • Score
    100M100P100Q17422F
  • License GPL-3.0

Package Exports

  • @vakhramoff/angular-utils

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 (@vakhramoff/angular-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Angular Utils

This library contains utils for Angular projects.

How to import it in your project:

import {
  EventBusService,
  HandleHttpErrors
} from '@vakhramoff/angular-utils';

Event Bus (Service)

How to import:

import { EventBusService } from '@vakhramoff/angular-utils';

Import service in any component's constructor:

constructor(private eventBus: EventBusService) {}

How to emit

Emit your message:

this.eventBus.emit({
  type: 'TEST_MESSAGE',
  payload: ['Test message payload']
});

How to subscribe

Listen to a specific type of messages in other part of your Angular app:

this.eventBus.on('TEST_MESSAGE').subscribe((payload) => {
  // do what you want with a payload...
});

HTTP Error Handler (Decorator)

Just decorate your methods which return Observables this way:

@HandleHttpErrors()
public getData(param: string): Observable<DataContract> {
  return this.http.get<DataContract>(`${environment.apiUrl}/data`);
}

The decorator takes one parameter (showAlert) whics is true by default, so if you catch any error, it will show a browser alert. In addition to that, this Decorator logs error into a console.

Cursor (Directive)

How to import:

import {
  DirectivesModule as AngularUtilsDirectivesModule
} from '@vakhramoff/angular-utils';

@NgModule({
  // ...
  imports: [
    // ...
    AngularUtilsDirectivesModule,
    // ^ add main library module to NgModule.imports section
    // ...
  ],
  // ...
})

Single-time Usage

Use in your template:

<div [cursor]="'pointer'">
  <!-- ... -->
</div>

Variable Binding

Or bind to some variable from the component:

  • example.component.ts:
public currentCursor: TCursorType = this.isEnabled ? 'pointer' : 'default';
  • example.component.html:
<div [cursor]="currentCursor">
  <!-- ... -->
</div>