I Am building an angularJS5 client using jhipster client and I encountered 'JhiEventManager' in login typescript file.
import { JhiEventManager } from 'ng-jhipster';
.....
constructor(
private eventManager: JhiEventManager,
...
}
...
...
this.eventManager.broadcast({
name: 'authenticationSuccess',
content: 'Sending Authentication Success'
});
I just want to know what is the purpose of JhiEventManager and how can I make use of it for other functionality? Is there any help or tutorial docs available?
JhiEventManager is a simple service that is part of the ng-jhipster. You can find the source code for this file at https://github.com/jhipster/ng-jhipster/blob/master/src/service/event-manager.service.ts
I couldn't find any documentation, but the code is really simple to follow along.
The functionality of the service is to serve as a wrapper to event subscription and broadcasting. For this, they have broadcast and subscribe methods.
In your example, you are broadcasting an event with the name of authenticationSuccess. What you can do with this is to simply listen to the changes from another component as follows:
//in the same or different component:
this.eventManager.subscribe('authenticationSuccess', () => {
console.log('authenticationSuccess called');
//todo: what you want to do when the event is broadcasted.
}
);
This is simply a wrapper for observables. You may wish to use observables directly instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With