2017-12-10 9 views
1

나는 jhipster 클라이언트을 사용하여 angularJS5 클라이언트를 구축 중이며 로그인 유형 스크립트 파일에 'JhiEventManage r'이 있습니다.JhiEventManager의 기능은 무엇입니까?

import { JhiEventManager } from 'ng-jhipster'; 
..... 
constructor(
     private eventManager: JhiEventManager, 
... 
} 
... 
... 
this.eventManager.broadcast({ 
     name: 'authenticationSuccess', 
     content: 'Sending Authentication Success' 
}); 

JhiEventManager의 목적이 무엇인지 알고 싶습니다. 어떻게 다른 기능을 위해 사용할 수 있습니까? 어떤 도움말이나 튜토리얼 문서가 있습니까?

답변

3

JhiEventManager은 ng-jhipster의 일부인 간단한 서비스입니다. 이 파일의 소스 코드는 https://github.com/jhipster/ng-jhipster/blob/master/src/service/event-manager.service.ts

찾을 수 있지만 코드는 따라하기가 정말 쉽습니다.

서비스의 기능은 이벤트 구독 및 브로드 캐스팅의 래퍼 역할을하는 것입니다. 이를 위해 broadcastsubscribe 방법이 있습니다.

예에서, 사용자는 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. 
    } 
); 

이는 관찰 대상에 대한 래퍼 일뿐입니다. 대신 Observable을 직접 사용할 수도 있습니다.