我正在使用jhipster客户端构建angularJS5客户端,并且在登录打字稿文件中遇到了“ JhiEventManage r”。
import { JhiEventManager } from 'ng-jhipster';
.....
constructor(
private eventManager: JhiEventManager,
...
}
...
...
this.eventManager.broadcast({
name: 'authenticationSuccess',
content: 'Sending Authentication Success'
});
Run Code Online (Sandbox Code Playgroud)
我只想知道JhiEventManager的用途是什么,如何将其用于其他功能?是否有任何帮助或教程文档?
JhiEventManager是ng-jhipster的一部分的简单服务。您可以在https://github.com/jhipster/ng-jhipster/blob/master/src/service/event-manager.service.ts中找到此文件的源代码。
我找不到任何文档,但是代码很容易遵循。
该服务的功能是充当事件订阅和广播的包装。为此,他们有broadcast和subscribe方法。
在您的示例中,您正在广播一个名为的事件authenticationSuccess。您可以执行的操作只是简单地听取来自另一个组件的更改,如下所示:
//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.
}
);
Run Code Online (Sandbox Code Playgroud)
这只是可观察对象的包装。您可能希望直接使用可观察对象。
| 归档时间: |
|
| 查看次数: |
1956 次 |
| 最近记录: |