Before I found out, it is better for my directive to be defined as follows:
... inputs: [ 'onOutside' ] ... export class ClickOutsideDirective { @Output() onOutside: EventEmitter<any> = new EventEmitter(); }
But then I read the stegid, and he said that you should not prefix outputs with on , since Angular 2 supports on- syntax in templates.
So, I'm trying to change it to something like:
@Input() outsideClick: any; @Output() outsideClick: EventEmitter<any> = new EventEmitter();
However, it is difficult for me to separate the @Input name from the Output name if you are not allowed to use the on prefix.
Before you could call the @Input and @Output same, but if you declare both in the exported class, then this no longer works, as an error will be raised.
If I call @Input to outside and @Output to outsideClick , that doesn't make sense, since both of them are the same thing. outside is the function I want to execute when calling outsideClick .
Also, outsideClick doesn't know what to do if outside no longer calls the same thing, or am I missing something?
How can I approach @Input and @Output variable names here so that they still work and have the same meaning as in the first example?
EDIT:
Usage example:
<div clickOutside [exceptions]="['.toggler']" (outside)="doSomethingOnOutsideClick()"></div>