I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4.
[plunkr] https://plnkr.co/edit/aKcZVQ?p=info
When I try using the same code in angular-4 I get the following errors:
1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> 
    @Component({
    templateUrl: "",
    directives: [ClickOutside]
    })
2. Type 'Subscription' is not assignable to type 'Observable<MouseEvent>'. in the directive inside ngOnInit() and ngOnDestroy() 
ngOnInit() {
    this.globalClick = Observable
        .fromEvent(document, 'click')
        .delay(1)
        .do(() => {
            this.listening = true;
         }).subscribe((event:MouseEvent) => {
            this.onGlobalClick(event);
         });
}
ngOnDestroy() {
    this.globalClick.unsubscribe();
}
If there is any change in the directive declaration in angular 4 please let me know, the official docs are of no help in this matter.
 
     
    