1.0.3 • Published 5 years ago

emiterr-event v1.0.3

Weekly downloads
15
License
-
Repository
-
Last release
5 years ago

EmiterrEvent

This library was generated with Angular CLI version 7.2.0.

Details

This library has functionality for issuing global applications in angular applications in order to be listened to by components in different hierarchies. This library also has the functionality of a service to manipulate and parse the data in the localStoraged and sessionStorage.

Usage

Issuing a global event

In the component in which we are going to trigger the event, we will import the EventEmitterService and only issue the event, it is quite simple:

import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { EventEmitterService } from "emiterr-event/src/lib/services/event-emitter.service";

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
export class FormComponent implements OnInit {

  data: any;

  constructor() { }

  ngOnInit() { }

  btnClick() {
    EventEmitterService.get('dataChange').emit(this.data);
  }

}

As you may note, the event was defined, dataChange. These events are dynamically created by passing their name to the get () method.

As get () returns an EventEmitter object, you just call the emit () method and fire the value you want with your event. In this document For example, typed 'date' is used like any, but you could pass other primitive types or a more complex object.

Signing (or Listening) Global Events

Signing (or Listening) Global Events Now it's time to register the classes that will listen to these events. The process is also simple, just import the service and, in the class constructor, tell which events you want to listen to:

import { Component } from '@angular/core';

import { EventEmitterService } from "./services/event-emitter.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    EventEmitterService.get('dataChange').subscribe(data => this.title = data);
  }

}

Developer by Anderson Machado

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago