simple events center for angular2 http module
Find a file
2017-06-05 09:29:50 +08:00
http-event.service.ts Update http-event.service.ts 2016-10-11 13:51:41 +08:00
LICENSE Initial commit 2016-10-11 11:54:03 +08:00
package.json publish to npm 2017-06-05 09:29:50 +08:00
README.md Update README.md 2016-10-11 13:06:06 +08:00

angular2-http-event

simple events center for angular2 http module

Usage

1. add decorator httpEmitter to http method

import { httpEmitter } from '/path/to/http-event.service';

class demoHttpService() {
  constructor(private http: Http) {}
  
  @httpEmitter
  query(args) {
    return this.http.get().map(response => response.json());
  }
}

now this method will emit 'START' and 'FINISH' events.

2. subscribe to http event

import { HttpEventService } from '/path/to/http-event.service';

@Component({...})
class DemoComponent implements OnInit {
  constructor(private httpEvent: HttpEventService) {}
  
  ngOnInit() {
    this.httpEvent.httpEventCenter.subscribe((type: HttpEventType) => {
      // event handler here...
    });
  }
}